PHP help needed

SnoopCat

Senior member
Jan 19, 2001
926
0
0
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
}
?>
 

SnoopCat

Senior member
Jan 19, 2001
926
0
0
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
 

darktubbly

Senior member
Aug 19, 2002
595
0
0
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).
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
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)
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
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.
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
*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
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
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.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |