I'm not a novice, but I'm not an expert either; I'm a keen learner.
Problem (minimalised) - I have a basic form which posts a name to another page which is supposed to receive name and print name. Code of both forms is below.
Form:
<?php
echo "Hello, World!";
echo "
<form action='CFAcomments.php' method='POST'>
<table style='width: 50%;' border='0'>
<tbody>
<tr>
<td><label for='name'>name: </label></td>
<td><input type='Text' name='name' value='anon' /></td>
</tr>
<tr>
<td><input type='submit' name='send' value='Send' /></td>
</tr>
</tbody>
</table>
</form>
";
?>
Form Process:
<?php
echo "Hello, World 1!";
echo "<br/>";
var_dump($_POST);
$name = $_POST("name");
echo "Hello $name!";
?>
Result:
Hello, World 1!
array(2) { ["name"]=> string(11) "anon" ["send"]=> string(4) "Send" }
Problem:
Even though var_dump($_POST) shows data being sent, echo $name print nothing. Changing echo $name to echo "test" prints nothing too. The code seems to stop executing at $name = $_post("name");. If I remove this line echo "anything" works.
I've used PHP and forms for the last two years and never come across this. Any help would be appreciated.
Array keys are referenced with square brackets, not parentheses.
$name = $_POST("name");
// Should be
$name = $_POST["name"];
That's because you're not using the right brackets. It has to be:
$_POST['name'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With