Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click submit in html and run php code [closed]

I am new to html & php and I appreciate your help. I am trying to accept user input into a webpage and then after the user clicks the submit button, write a new record out to MySQL. I am using Wordpress so the tags are not exactly textbook.

So my first problem is that the submit button does not appear to execute the php code. I also would appreciate it if someone could check how I am passing my html field names to the php variables to make sure that I am on the right track. Thanks 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">
like image 566
Sandy Stokes Avatar asked Aug 11 '13 21:08

Sandy Stokes


2 Answers

I think it can be good to read a bit more about it. Check here.

Anyway, you need to say the name of the file to post to: <input type="submit" action="file.php" name="Submit" /> for example.

And you need to have more inputs than the submit.

Acording to your php you should have as example this in the 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 to open, and ?> to close.

So like:

<?php
    if(isset($_POST['Submit'])) {
        $FName = $_POST['FName'];
        $MI = $_POST['MI'];
        $LName = $_POST['LName'];
//....
?>
like image 112
Sergio Avatar answered Oct 19 '22 03:10

Sergio


Your PHP tags are incorrect. Use <?php and ?> to tell PHP to start and stop interpreting the code between them. Also, make sure you're closing the form element (I only see you're opening it) using </form> and that you indeed have all those fields contained inside of it.

like image 26
federico-t Avatar answered Oct 19 '22 04:10

federico-t