By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,066 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,066 IT Pros & Developers. It's quick & easy.

Upload image to Mysql with PHP fails

P: 2

I am really bashing my head on this one. I have an image I have manipulated, now I want to push it back to the database.

So, to accomplish this, I have the following:

--- $image_file = fopen ('/var/tmp/tmp.jpg','rb');
$image_data = fread ($image_file, filesize ('/var/tmp/tmp.jpg'));
$image_data = addslashes ($image_data);
fclose ($image_file);

$sql = "UPDATE article_attachment SET content = $image_data where id = $article_data[0]";

$image_update = mysql_query ($sql);

echo mysql_error($dbi);
It's more drawn out than it should be, but I am breaking everything down to try and solve this. I get the 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 '▒▒▒▒\0JFIF\0\0\0\0\0\0▒▒\0>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), defa' at line 11"

I see some high order characters that don't appear to be getting escaped properly, should this be happening?...

Aug 5 '14 #1
Share this Question
Share on Google+
1 Reply

P: 2
Found the issue. In my sleep deprived state, I had reused the $image_data variable. It was already an array, and I was re-casting image data into it. Made for some confusion.
Aug 6 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.