I have an HTML form as follows:
<form enctype="multipart/form-data" action=" " method="post">
<input name="username" type="text"/>
<input type="submit" value="Upload" class="btn btn-primary"/><br/>
</form>
I want that the user of this form enters data in the input box. Then I would like this data to be the value of a PHP string – e.g. $username = "MY_NAME"; where MY_NAME is the value of the HTML form entered by the user.
If the input by the user in the input box is e.g. "STACKOVERFLOW" I want the PHP string to be $username = "STACKOVERFLOW";
When the form submits, you need to get the values from the
$_POSTarrayYou can do
print_r($_POST)to see everything it contains (all of the form fields) and reference them individually as well.Username will be
$_POST['username']I recommend reading a tutorial on working with forms and PHP… here’s a good one
Since you’re obviously a beginner I’ll help you out a bit more:
Give your submit button a name:
Because
actionis blank, it will POST to the current page. At the top of your file, you can check to see if the form was submitted by checking if$_POST['submit']is set (I gave your submit button that name).