# [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.

## 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>
<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 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: <?phpecho "value 1:${_POST['val1']} <br> value 2: ${_POST['val2']}";?>  #### Share this post ##### Link to post ##### Share on other sites The values are in$_POST['val1'] I believe.
EDIT: mattd said it better =)

Thanks.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 11
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632649
• Total Posts
3007644
• ### Who's Online (See full list)

There are no registered users currently online

×