PHP are
great for processing input forms ... Just look at this form:
<html>
<body>
<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">
</form>
</body>
</html>
To get the submitted values, this code will suffice:
<?php
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
Username is
Notice: Undefined variable: age in ......\test.php on line 4
Age is
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" file.
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 again.
(Any reason why?)
Security issue.
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.