我在PHP中有一个MySQL语句将一行移动到另一个表但它仍然显示:
*您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第1行的“1”附近使用正确的语法 *
这是我的代码:
$sql = mysqli_query($conn,"
INSERT INTO userdocs
SELECT transaction_no
, document_type
, date_received
, application_no
, hei
, school_name
, from_co
, other_govt
, contact_person
, comment
, program
, year_level
, academic_year
FROM records
WHERE transaction_no = '$transaction_no'
");
if(!mysqli_query($conn, $sql))
{
echo (mysqli_error($conn));
}
else
{
echo "Document Sent! Going back to Home Page...";
header("refresh:3; url=director.php");
}
答案 0 :(得分:1)
可能包含$transaction_no
会导致格式错误。尝试检查SQL语句。通常,在处理动态参数时应使用预处理语句:
$stmt = $db->prepare('insert into userdocs select transaction_no, document_type, date_received, application_no, hei, school_name, from_co, other_govt, contact_person, comment, program, year_level, academic_year from records where transaction_no = ?');
$stmt->bind_param('s', $transaction_no);
$result = $stmt->execute();
或使用PDO。