我正在尝试将表单输入到数据库中,但是显示两个不同的错误
"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"
我尝试删除“ @”符号,但出现了这种情况:
"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'"
这是我的代码
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();
在macOS Mojave上通过xampp使用phpmyadmin即时通讯
答案 0 :(得分:0)
在您的值中添加单引号以表示字符串,并根据您的列正确重新排列值(您错位了phonenumber
和email
列值序列)
$sql= "INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values($firstname, $surname, $email, $phonenumber, $Localmovie, $session, $day)";
收件人
$sql= "INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values('$firstname', '$surname', '$phonenumber', '$email','$Localmovie', '$session', '$day')";