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