I’m trying to have an array display information inputted from a PHP-created HTML form. I’m trying to get the entire code on to one PHP file. So far, I have:
<body>
<form action="hello.php" method="post">
<input type="text" name="input" placeholder="Number" />
<input type="submit" value="submit" onclick="go()" />
</form>
</body>
The above code is generated using “echo” in PHP (not shown).
Then for the rest of the PHP, I have:
function go() {
$variable = "input";
That is just the beginning of my code. The rest is unimportant. I know the $variable = “input”; part is wrong, but how do I get numbers to transfer over from inputted HTML to PHP? Thanks a lot!
Since you’re using a POST request you’re going to want to refer to the
$_POSTsuperglobal. This variable is an array filled with any information sent by a POST request.Since you want to get the value from “input” you would call the the
$_POSTvariable using the key of “input”Since
$_POSTis a superglobal it is global in every scope.You don’t need to include the onclick event for your submit button, unless you wanted to call a JavaScript event with it. But the mapping of the JavaScript function go() and the PHP function go() have ZERO correlation between the two.