I'm new to PHP and I'm not sure what I'm doing wrong. I can open the html form and give the data but when I hit submit it shows me the php code and the database is (obviously) not updated. I have tried inserting values to the table manually through phpMyAdmin and it works. I have looked online but me syntax looks fine (to me). Am I doing some different wrong? If the mistake is not too obvious is there an efficient way to debug (ie see the errors)?
I have this HTML code
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Hotel Start Page</title>
</head>
<body>
<form action="customerCreate.php" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<header align="center"> <b>Customer Sign Up</b></header>
<p><b>Surname: </b><input type="text" name="surname" size="30" maxlength="40"/></p>
<p><b>Name: </b><input type="text" name="name" size="30" maxlength="40"/></p>
<p><b>E-mail: </b><input type="text" name="email" size="30" maxlength="40"/></p>
<p><b>Telephone: </b><input type="text" name="tel" size="30" maxlength="10"/></p>
<p><b>Password: </b><input type="password" name="passwd" size="30" maxlength="10"/></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Create Account"/></div>
</form>
</body>
This PHP code
<?php
$host = 'localhost';
$username = 'root';
$password = '';
$db = 'my_hotel';
$conn = new mysqli($host,$username,$password,$db);
if ($conn->connect_error) {
die("Connection Error: " .$conn->connect_error);
}
$sname = $_POST['surname'];
$name = $_POST['name'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$passwd = $_POST['passwd'];
$sql = "INSERT INTO Customer (sname, name, email, tel, passwd) VALUES
(?,?,?,?,?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssss",$sname,$name,$email,$tel,$passwd);
$stmt->execute();
$cid = "SELECT cid FROM Customers WHERE sname='$sname' AND passwd='$passwd' ";
$result = $conn->query($cid);
$row = $result->fetch_assoc();
echo "Customer Added.<br>";
echo "Your Customer ID is ".$row['cid'];
$stmt->close();
$conn->close();
?>
And this table in a database called My_hotel in phpMyAdmin
CREATE TABLE Customer (
cid INT AUTO_INCREMENT,
sname VARCHAR(15),
name VARCHAR(15),
email VARCHAR(15),
tel VARCHAR(15),
passwd VARCHAR(15),
PRIMARY KEY (cid)
);