• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP help needed

SnoopCat

Senior member
im getting the following error message

Notice: Undefined index: action in C:\Program Files\Apache Group\Apache2\htdocs\steve\8-3.php on line 2

The problem is that a friend of mine is running the same thing and does not get that error message.
We are using the same version of apache and php. I probably didnt setup something right in a config file somewhere but we both cant figure out what.
Does anyone know why I am getting the error message?




the 8-3.php code:





<?php
if ($HTTP_POST_VARS['action'] == 'submitted') {
print '<pre>';

print_r($HTTP_POST_VARS);
print '<a href="'. $HTTP_SERVER_VARS['PHP_SELF'] .'">Please try again</a>';

print '</pre>';
} else {
?>
<form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
Name: <input type="text" name="personal[name]">

Email: <input type="text" name="personal">

Beer:

<select multiple name="beer[]">
<option value="warthog">Warthog</option>
<option value="guinness">Guinness</option>
<option value="stuttgarter">Stuttgarter Schwabenbr&auml;u</option>
</select>

<input type="hidden" name="action" value="submitted">
<input type="submit" name="submit" value="submit me!">
</form>
<?php
}
?>
 
I tried changing it and it came up with the same result... note that my friend's server doesnt complain with this code. We are using the same php and apache versions
 
Try this instead...


if ( isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] == 'submitted') {
print '<pre>';
...

As BingBongWongFooey suggested, those are pretty outdated. Modern versions of PHP use $_POST and $_SERVER. Also, even though you and your friend may have the same versions of PHP/Apache, they may be configured differently (i.e.: register_globals might be turned on).
 
a notice and an error message arent the same....all its telling you is that the variable "action" has yet to be created and therefore the if cannot be preformed so its going to go to the else..
I always turn off the "Notices" in the PHP ini file just cause there useless...prettymuch telling you that variables aren't declared and stuff like that. You have the option to display errors, warnings, and notices....I do erros and warnings since they actually have bearing on your program...wheras the notices do not really.
Now if your program is not working when you post you might want to make sure that you are allowed to post (yet another thing to turn on in the ini file)
 
Originally posted by: Drakkon
a notice and an error message arent the same....all its telling you is that the variable "action" has yet to be created and therefore the if cannot be preformed so its going to go to the else..
Well technically the variable is set, but the array key does not exist.

I always turn off the "Notices" in the PHP ini file just cause there useless...prettymuch telling you that variables aren't declared and stuff like that.
THIS is why people joke about php not being actual programming. Trying to access an undeclared variable should be a fatal error IMO, it should never happen in good code.

You have the option to display errors, warnings, and notices....I do erros and warnings since they actually have bearing on your program...wheras the notices do not really.
I like to run with error_reporting(E_ALL). Any good code should run with E_ALL and not produce any notices or errors. Notices *do* have a bearing on your code, they either tell you that you're coding sloppily or they let you know about things that are deprecated and might disappear one day. PHP coders already have huge problems because anyone's grandma can pick up PHP easily and as a result, a lot of php code out there is horrible.
 
*shudders in his corner at wooeys fury*
I just wanted to point out that the notices shouldn't be causing his program to not run...
I dunno....the on the fly variable creation was what always intreiged me about php...esp when register globals was around and were able to take form input feilds and automatically have them turn variable...sure vars should be declared but in a way your doing that in the post/input fields of whatever form your processing from. Thats the way i look at it at least...and with functions like isset, isstring, etc, am able to do all the var handling that makes since to me 😛
 
Originally posted by: Drakkon
*shudders in his corner at wooeys fury*
😛

I just wanted to point out that the notices shouldn't be causing his program to not run...
I don't know what you mean -- of course a notice won't cause a script to not run.

I dunno....the on the fly variable creation was what always intreiged me about php...esp when register globals was around and were able to take form input feilds and automatically have them turn variable...sure vars should be declared but in a way your doing that in the post/input fields of whatever form your processing from.Thats the way i look at it at least...and with functions like isset, isstring, etc, am able to do all the var handling that makes since to me 😛

You are misunderstanding me. Your *own* variables should be declared before use. Of course you can't declare server-generated variables, I was not suggesting that.
 
Back
Top