Issue
i'm trying to input a form into my database, but there are two different errors showing
"Error: INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values(jon, doe, johndoe@icloud.com, 123456789, halloween, afternoon, tuesday)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 '@icloud.com, 123456789, halloween, afternoon, tuesday)' at line 3"
i tried removin the "@" sign but instead this came up:
"Error: INSERT INTO movie (firstname, surname, phonenumber, email,
movie, session, day) values(jon, doe, johndoeicloud.com, 123456789,
halloween, afternoon, tuesday)Unknown column 'jon' in 'field list'"
This is my code
if (!empty($firstname) || !empty($surname) || !empty($email) || !empty($phonenumber) || !empty($Localmovie) || !empty($session) || !empty($day)) {
$host = "localhost";
$dbUsername= "root";
$dbPassword="";
$dbName="tickets";
//create connection
$conn= new mysqli($host, $dbUsername, $dbPassword, $dbName);
if (mysqli_connect_error()) {
die('Connect
Error('.mysqli_connect_errno().')'.mysqli_connect_error());
}else{
//$sql = "INSERT INTO tutorials_inf(name)VALUES ('".$_POST["name"]."')";
$sql= "INSERT INTO movie
(firstname, surname, phonenumber, email, movie, session, day)
values($firstname, $surname, $email,
$phonenumber, $Localmovie, $session, $day)";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "" . mysqli_error($conn);
}
$conn->close();
im using phpmyadmin through xampp on macOS Mojave
Solution
Add single quotes to your value for string representation and also properly re-arrange the values based on your columns(You miss-places phonenumber
and email
column-value sequence)
$sql= "INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values($firstname, $surname, $email, $phonenumber, $Localmovie, $session, $day)";
To
$sql= "INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values('$firstname', '$surname', '$phonenumber', '$email','$Localmovie', '$session', '$day')";
- The date and string values should be enclosed in single quotes.
- The numeric values do not need to be enclosed in quotes.
Answered By - Always Sunny
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.