使用php将HTML表单提交到数据库时,只显示php脚本[重复]

This question already has an answer here:

I have a html page that has a form which should submit some data to a database. I have linked it to php file. Whenever I press submit, it goes to the php file but it does not submit anything to the database. Instead, it shows the 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'm not quite what's wrong with this code. Please help! Thank you

</div>

You need to add a name to the submit button.

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

把表单加入脚本程序,放在web服务器默认支持的目录中。