Jump to content
  • Advertisement
Sign in to follow this  

[web] Why can't I get form data?

This topic is 3254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I haven't used PHP in a while and I'm trying to get into it again. For some reason, I can't get any form data. This is my form page:
<head><title>Test Page</title></head>
<h2>Data Collection</h2><p>
<form action="process.php" method="post">
<tr><td>value 1:</td><td><input type="text" name="val1" /></td></tr>
<tr><td>value 2</td><td><input type="text" name="val2" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" /></td></tr>

echo "value 1: $val1 <br> value 2: $val2";

The values are always blank. Could there something wrong with my PHP settings?

Share this post

Link to post
Share on other sites
It is because of your settings, yes, but saying that they are "wrong" isn't quite right :)

You are relying on register_globals being on. This predefines variables in your script corresponding to, among other things, any input data supplied by a client's submitted form. As you can see from the warnings all over that page, this is/was a bad idea, and shouldn't be used now.

You should instead use the superglobals, $_GET, $_POST, and $_REQUEST as necessary.

For your process.php, like this:

echo "value 1: ${_POST['val1']} <br> value 2: ${_POST['val2']}";

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!