PHP are great
for processing input forms ... Just look at this form:
<form action="process.php" method="post">
What is your name: <input name="username" type="text"><br>
What is your age: <input name="age" type="text"><br>
<input name="Submit" type="submit" value="Submit Now">
To get the submitted values, this code will suffice:
echo("The user's name is " . $username);
echo("The user's age is " . $age);
( Simply cool! ... You might be thinking already...)
Now go on ... Run the code and see what you get ...
Do you get this result?
The user's name is John. (Assuming you entered Jack)
The user's age is 23. (Assuming you entered 23)
No? Do you get an error
( Yep. What am I doing wrong? ... Are you wondering? )
Let's see ... if you encounter the following error, you are not alone ...
Notice: Undefined variable: username in ......\test.php on line 3
Notice: Undefined variable: age in ......\test.php on line 4
Almost every PHP newbie suffers from this maddening experience. A simple form exercise turns out to be minutes (hopefully not hours ...) of debugging.
Luckily for you, you won't suffer the same trauma.
The reason why this error occur lies in the "php.ini"
Look for register_globals = off
. Turn it on
and try again.
You should be popping champagne this time! Well let's not be estatic.
Although it works for now, it might be better to turn it off
(Any reason why?)
If someone create a bogus form with tonnes of input fields and send it to your php script, your script will end up with tonnes of landmines in the global register.
Sounds bad enough?
Remember to turn it off.