我在通过 php 向 MySQL 提交一些数据时遇到问题,我收到以下错误:
“错误:您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,了解在“学生”附近使用的正确语法(UID、名字、姓氏、出生日期、紧急联系人、地址、城市、州)在第 1 行"
我不确定我哪里出错了,任何帮助都会很棒。
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$dob = $_POST['dob'];
$emergencycontact = $_POST['emergencycontactperson'];
$address = $_POST['addressline1'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$homephone = $_POST['homephone'];
$cellphone = $_POST['cellphone'];
$guardian = $_POST['guardian'];
$inneighborhood = 0;
if ($zip == "49503")
$inneighborhood = 1;
$con = mysqli_connect("localhost", "cookarts_root", "password", "cookarts_database");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "INSERT INTO 'student' (FirstName, LastName, DOB, EmergencyContact, Address, City, State, ZIP, CellPhone, HomePhone, Guardian, InNeighborhood)
VALUES
($firstname', '$lastname', '$dob', '$emergencycontact', '$address', '$city', '$state', '$zip', '$cellphone', '$homephone', '$guardian', '$inneighborhood')";
if ($con->query($sql) === TRUE) {
echo 'users entry saved successfully';
}
else {
echo 'Error: '. $con->error;
}
mysqli_close($con);
?>
如果您需要更多信息,我很乐意提供,再次感谢您的帮助。