开发者

Error Uploading JPEG to MySQL

I am getting the error below when trying to upload an JPEG image to my MySQL database (Image is a BLOB):

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 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 id=57 (Image)  VALUES ('ÿØÿà\0JFIF\0\0\0\0\0\0ÿá\0XExif\0\0MM\0*\0\0\' at line 1

I would really appreciate if you could tell me the problem in my code.

$sql = sprintf(
"INSERT INTO recipies WHERE id=$id (Image) VALUES ('%s')", mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"])));
$results = mysql_query($sql) or die(mysql_error());


Its insert into or update where.

You might want this:

$sql = sprintf(
"UPDATE recipies SET Image = '%s' WHERE id=$id", mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"])));
$results = mysql_query($sql) or die(mysql_error());


Maybe like this would be more correct syntax

$sql = sprintf(
"INSERT INTO recipies (Image) VALUES ('%s') ", mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"])));
$results = mysql_query($sql) or die(mysql_error());

EDIT

It seems you're confused with SQL UPDATE syntax and MySQL particular mess. So correct syntax would be

INSERT
    [INTO] tbl_name [(col_name,...)]
    {VALUES | VALUE} ({expr | DEFAULT},...),(...),...

Or:

INSERT 
    [INTO] tbl_name
    SET col_name={expr | DEFAULT}, ...

So you friend is the MySQL::INSERT Syntax Manual. Happy Querying!


Looks more like you are trying to update rather than insert

UPDATE recipes SET Image= ('%s') WHERE id = %d
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜