Press submit in html and run php code

I am new to html and php and I appreciate your help. I am trying to accept user input to a web page, and then, after the user clicks the submit button, write a new entry in MySQL. I use Wordpress, so tags are not tutorials.

So, my first problem is that the submit button does not execute the PHP code. I would also appreciate if someone could check how I pass my html field names to php variables to make sure I'm on the right track. Thank you for your help!

html code to collect user input for fields on the form..... <?php> if(isset($_POST['Submit'])) { $FName = $_POST['FName']; $MI = $_POST['MI']; $LName = $_POST['LName']; .... ?> <form action="" method="post"> <input type="submit" name="Submit" value="Submit"> 
+6
source share
2 answers

I think it’s nice to read a little more about it. Check here .

In any case, you need to specify the file name for publication: <input type="submit" action="file.php" name="Submit" /> for example.

And you need to have more input than send.

According to your php you should have this as an example in html:

 <form action="your_php_file.php" method="post"> <p>Your first name: <input type="text" name="FName" /></p> <p>Your last name: <input type="text" name="LName" /></p> <p>Your MI: <input type="text" name="MI" /></p> <p><input type="submit" name="Submit"/></p> </form> 

And the php tags are like <?php , and ?> Closes.

So how:

 <?php if(isset($_POST['Submit'])) { $FName = $_POST['FName']; $MI = $_POST['MI']; $LName = $_POST['LName']; //.... ?> 
+9
source

Your PHP tags are incorrect. Use <?php and ?> To tell PHP to start and stop interpreting the code between them. Also, make sure that you close the form element (I see that you open it) with </form> and that you really have all the fields contained inside it.

0
source

Source: https://habr.com/ru/post/951514/


All Articles