When submitting HTML form to database using php, only PHP script is displayed

I have a html page that has a form that needs to submit some data to a database. I linked it to a php file. Whenever I click the submit button, it goes to the php file, but it doesn't submit anything to the database. Instead, it shows php code.

Here's my HTML

<html>

<body>
    <form action="insert.php" method="post">
        <fieldset>
            <legend>Name</legend>
            Firstname:
            <input type="text" name="firstname" />
            <br>
            <br> Lastname:
            <input type="text" name="lastname" />
            <br>
            <br>
        </fieldset>
        <input type="submit" />
    </form>
</body>

</html>

      

Here's the PHP code

<?php

$user_name = "sql683849";
$password = "*******";
$database = "sql683849";
$server = "sql6.freemysqlhosting.net";

mysql_connect("$server", "$user_name", "$password");

mysql_select_db("$database");

if (isset($_POST['submit'])) {
    $firstname = $_POST['firstname'];
    $lastaddress = $_POST['lastname'];

    $order = mysql_query("INSERT INTO nametable (firstname, lastname) VALUES ('$firstname', '$lastname)");

    if ($order) {
        echo '<br>Input data is successful';
    } else {
        echo '<br>Input data is not valid';
    }
}
?>

      

I am not completely wrong about this code. Please help! Thanks you

+3


source to share


1 answer


You need to add a name to the submit button.



<input type="submit" name="submit" />

      

-1


source







All Articles