我有一個INSERT語句中,我收到以下錯誤消息:並不能解決這個SQL錯誤
Error: 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 'WHERE ref = '6u5i14e'' at line 1
這是我的PHP文件:
<?php
$secret_question = mysql_real_escape_string($_REQUEST['secret_question']);
$secret_anwser = mysql_real_escape_string($_REQUEST['secret_anwser']);
$con = mysql_connect("localhost","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('*****', $con);
$sql="INSERT INTO public (secret_question, secret_anwser) VALUES ('$secret_question','$secret_answer') WHERE ref = '". $_SESSION['ref']."' ";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else
{
echo '<hr><h3>Your Account Has Now Been Activated. <br/> <a href = "votenow.php">Please Login To Vote</a></h3><hr>';
}
?>
我到底做錯了什麼?
INSERT ...在沒有有效的SQL語法,是嗎? :) – 2012-02-24 17:34:02
順便說一句,您在開始時使用'$ secret_anwser',然後在查詢中使用'$ secret_answer'。 – 2012-02-24 17:35:28
確保你還有'mysql_real_escape_string()'會話值。在會話中存儲值不會*轉義它 – 2012-02-24 17:39:05