I am working on creating my portfolio website. As a part of it, I created a contact form that is connected to MySQL. I want the data from the contact form to be inserted into my table. Now when I just do it normally (I will post the code below), it is working fine but when I try to create a stored procedure it is not working. My code which is working:
<?php
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
//Database connection
$conn = new mysqli('localhost', 'root', '', 'portfolio');
if($conn->connect_error){
die('Connection Failed: '.$conn->connect_error);
}
else{
$stmt = $conn->prepare("insert into contact_info(email, subject, message) values(?, ?, ?)");
$stmt->bind_param("sss", $email, $subject, $message);
$stmt->execute();
echo "Message Received! Karthik will get back to you shortly!!";
$stmt->close();
$conn->close();
}
?>
Now when I try it using a procedure it is not working. Here is the code I used in my php file:
<?php
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
//Database connection
$conn = new mysqli('localhost', 'root', '', 'portfolio');
if($conn->connect_error){
die('Connection Failed: '.$conn->connect_error);
}
else{
$stmt = $conn->prepare("CALL putInfo(:email,:subject,:message);");
$stmt->bind_param("sss", $email, $subject, $message); //problem area not able to figure out how to do this.
$stmt->execute();
echo "Message Received! Karthik will get back to you shortly!!";
$stmt->close();
$conn->close();
}
?>
The error message I am receiving:
Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':email,:subject,:message)' at line 1 in C:\xampp\htdocs\portfolio\connect.php:12 Stack trace: #0 C:\xampp\htdocs\portfolio\connect.php(12): mysqli->prepare('CALL putInfo(:e...') #1 {main} thrown in C:\xampp\htdocs\portfolio\connect.php on line 12
My table schema: