I try to do the booking form and in the PHP I type the $stmt->bind_param
part come out syntax error. However, I don’t know where I did wrong. Here is my phpMyAdmin setting phpmyadmin table structure:
. Below is my code:
$conn = mysqli_connect($servername, $username, $password,$database);
// Check connection
if($conn->connect_error){
die("Connection Failed : ". $conn->connect_error);
} else {
$stmt = $conn->prepare("insert into event_and_inquiry_form (Name,Mail,Phone_Number,Date,Propose,Person,Theme,Event_Package,Remarks)VALUES (Name, Mail, Phone_Number,Date,Propose,Person,Theme,Event_Package,Remarks);
$stmt->bind_param("sssisisss", $Name,$Mail,$Phone_Number,$Date,$Propose,$Person,$Theme,$Event_Package,$Remarks);
$execval = $stmt->execute();
echo $execval;
$stmt
$stmt->close();
$conn->close();
}
2
Answers
You do happen to have a few issues.
?
. I believe you can hold them with:name :secondname
as well but that’s a story for another question.I corrected your code with what I noticed and posted it below:
It seems you’re getting confused between
mysqli
andPDO
– although there are syntax issues either way!mysqli
With
mysqli
the short answer is that you need to replace all of the variables inVALUES( ... )
with?
.PDO
You can do it the same way in
PDO
.Of course the connection method is different and we’ll pass an array of the values to the execute function instead.
Finally, in some cases you may prefer to name your placeholders. In this case the name will be
:some_name
and the array will need to be associative["some_name"=> "Some value"]
.