Tôi nhận được lỗi này từ MySQL:MySQL Lỗi: "một lỗi trong cú pháp SQL của bạn; kiểm tra hướng dẫn tương ứng với phiên bản máy chủ MySQL của bạn cho đúng cú pháp"
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'Details
(title, first, last, NRIC, po' at line 1
Đây là mã:
<?php
$link = mysql_connect("localhost", "root", "");
if (!$link) { die('Could not connect: ' . mysql_error()); }
$db_selected = mysql_select_db(Membership, $link);
if (!$db_selected) { die('Can\'t use' . Membership . ':' . mysql_error()); }
$value1 = $_POST["title"];
$value2 = $_POST["first"];
$value3 = $_POST["last"];
$value4 = $_POST["NRIC"];
$value5 = $_POST["birthdate"];
$value6 = $_POST["birthmonth"];
$value7 = $_POST["birthyear"];
$value8 = $_POST["address"];
$value9 = $_POST["postal"];
$value10 = $_POST["genderSelect"];
$value11 = $_POST["contact"];
$value12 = $_POST["email"];
$value13 = $_POST["enter"];
$value14 = $_POST["password"];
$value15 = $_POST["Updates"];
$value16 = $_POST["Terms"];
$value17 = $_POST["submit_but"];
$value18 = $_POST["status"];
$sql = "INSERT INTO Member Details (title, first, last, NRIC, birthdate, birthmonth, birthyear, address, postal, genderSelect, contact, email, enter, password, Updates, Terms, submit_but, status) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18')";
if (!mysql_query($sql)){ //The error is thrown here
die('Error: ' . mysql_error());
}
mysql_close();
?>
MySQL cung cấp cho bạn lỗi này khi truy vấn SQL của bạn là để bị thay đổi mà nó thậm chí không thể bắt đầu hiểu những gì bạn đang cố gắng làm và thay vì đưa ra lời khuyên nhắm mục tiêu theo ý bạn muốn, nó sẽ cho bạn biết "hãy đọc hướng dẫn". Vì vậy ... Hãy đọc hướng dẫn: http://dev.mysql.com/doc/refman/5.0/en/select.html –
@EricLeschinski Trong khi nó chỉ là một bình luận nó làm cho tôi nhận ra vấn đề của tôi là gì - một tên trường là hợp pháp trong MSSQL nhưng là một từ dành riêng trong MySQL. –