Jump to content
  • Advertisement
Sign in to follow this  
ManaStone

[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:
<html>
<head><title>Test Page</title></head>
<body>
<h2>Data Collection</h2><p>
<form action="process.php" method="post">
<table>
<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>
</table>
</form>
</body>
</html> 


process.php
<?php
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
Advertisement
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:

<?php
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!