Reputation: 13
I am trying to insert emails into a MYSQL table, and I am getting an 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 ' 19, '[email protected]')' at line 1
I've looked over the internet, and tried different combinations of collations and codes, but nothing will work. Is the '@' the problem here? I am getting this email address from decoding Facebook's JSON user object. Here are snippets from my code:
$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 is a bigint, access is a varchar, gender is a binary, age is an int, and email is a varchar.
Thanks for your help!
Upvotes: 0
Views: 2056
Reputation: 11385
@ signs are fine in text. I believe it's your "gender" value that's probably causing the error -- you should echo out the full query.
Upvotes: 0
Reputation: 33457
false casts as a string to an empty string. An empty string is not valid in SQL for an integer column (or a column value of any kind since it won't have a '' either).
Instead of false/true use 0/1.
Upvotes: 4