christh Posted February 12, 2010 Share Posted February 12, 2010 Hi forum members I hope you can help me. If I have a table that contains uploaded documents stored in a MediumBlob - can I move it/insert a MediumBlob field into another table in the same ways as I would and INT or VarChar? I can download and view the documents without issue but I'd like to move certain records to another table using a Query/Insert INTO however the insert fails if I include the MediumBlob field within the query. Everything is inserted if I drop the MediumBlob field which makes me suspect I need to treat this type of data in a different fashion or do I have an error else where? - I've spend 2 hours double checking my script and I can't spot a typo... mysql_query ("INSERT INTO data_main (date, name, telephone, location, status, email, fname, size, type, content ) VALUES ('$date','$name', '$telephone', '$location', '$stat', '$email', '$fname', '$size', '$type', '$content')"); content / $content is the MediumBlob field and is extracted and stored from a standard query $content=$row['content']; I've used an echo statement to confirm that the data is stored in $content however it just won't insert - With it removed from the insert query the insert. Hopefully my problem is easy enough to follow and thanks in advance. Chris Quote Link to comment https://forums.phpfreaks.com/topic/191886-insert-query-containing-mediumblob/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 12, 2010 Share Posted February 12, 2010 It sure would be nice if you showed us the data that was causing your query to fail, but best guess is that it contains SQL special characters that should be escaped before being put into a query so that the syntax of the query is not broken. Quote Link to comment https://forums.phpfreaks.com/topic/191886-insert-query-containing-mediumblob/#findComment-1011401 Share on other sites More sharing options...
christh Posted February 12, 2010 Author Share Posted February 12, 2010 Hi and thanks for getting back to me. More than happy to post anything you feel would be helpful - what do you mean by data? The actual contents of the table or the query that extracts the data from the table. The mediumblob ($content) is an uploaded Word doc. Sorry for being dim. Chris Quote Link to comment https://forums.phpfreaks.com/topic/191886-insert-query-containing-mediumblob/#findComment-1011415 Share on other sites More sharing options...
christh Posted February 12, 2010 Author Share Posted February 12, 2010 Hi again Thanks for pointing me in the right direction and you were spot on - after reading up, if you want to insert binary data into a BLOB column it needs to be escaped. I added the following to my initial query $content=$row['content']; $content = addslashes($content); The insert query then worked. Again thanks for your help. Chris Quote Link to comment https://forums.phpfreaks.com/topic/191886-insert-query-containing-mediumblob/#findComment-1011434 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.