我試圖插入電子郵件到MySQL表,我得到了一個錯誤:輸入電子郵件地址到MySQL數據庫
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 ' 19, '[email protected]')' at line 1
我看過了互聯網,並試圖排序規則和規範的不同組合,但沒有任何工作。這裏的'@'是問題嗎?我從解碼Facebook的JSON用戶對象獲取此電子郵件地址。下面是摘錄從我的代碼:
$user = json_decode(file_get_contents($jsonurl));
$userid = $user->id;
if($user->gender == "male") $usergender = TRUE;
else $usergender = FALSE;
$useremail = $user->email;
mysql_select_db("kirkstat", $con);
$result = mysql_query("INSERT INTO table (id, access, gender, age, email) VALUES ($userid, '$access_token', $usergender, 19, '$useremail')");
if (!$result){
echo("error.\n");
die('Invalid query: ' . mysql_error());
}
ID是一個BIGINT,訪問是VARCHAR,性別是一個二元的,年齡是一個int和電子郵件是一個varchar。
感謝您的幫助!
$ usergender應該引用'$ usergender'只有數字不需要引號。 – bumperbox 2012-03-12 06:54:51