Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the php script
<?php

if(isset($_POST['name'])){
$yourName = $_POST['name'];
}

if(isset($_POST['email'])){
$yourEmail = $_POST['email'];
}

if(isset($_POST['comment'])){
$yourComment = $_POST['comment'];
}

$conn = new mysqli('localhost', 'root', '','regisdata');

if($conn->connect_error){
    die('Connection Failed : ' .$conn->connect_error);
}
else
{
    $stmt = $conn->prepare("INSERT INTO guest_records('name', 'email', 'comment') VALUES (?, ?, ?)");
    
        if($stmt !== FALSE)
        {
            $stmt->bind_param("sss", $yourName, $yourEmail, $yourComment);
            $stmt->execute();
            $stmt->close();
            $conn->close();
            header("Location: guestbook.php?Success");
        }
}

?>


What I have tried:

I have other project that already working using that php code but it bothers me it doesn't work on this project. When i click the submit just a blank php page and no errors and it suppose to return to the form.
Posted
Updated 30-Apr-20 5:23am
Comments
MadMyche 30-Apr-20 10:54am    
Have you verified that all of those variables are populated (name etc)

1 solution

Quote:
SQL
INSERT INTO guest_records('name', 'email', 'comment') VALUES (?, ?, ?)
According to the documentation[^], you can't use single quotes around object identifiers.

You can use backticks:
SQL
INSERT INTO guest_records(`name`, `email`, `comment`) VALUES (?, ?, ?)
or, if ANSI_QUOTES is enabled, double quotes:
SQL
INSERT INTO guest_records("name", "email", "comment") VALUES (?, ?, ?)
 
Share this answer
 
Comments
oceanotrash 1-May-20 2:34am    
It worked! thank you @richard deeming

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900