kate_rose Posted June 22, 2008 Share Posted June 22, 2008 Someone over in the mysql help section suggested that I have incorrect syntax in the snippet of code below. I have always used the periods and double quotes to put a php variable into a mysql query but I am very new at this so maybe it does need to be changed. Specifically I am refereding to the $savetodb variable syntax. I am trying to send a serialized array to a mysql db. <?php $query = "INSERT INTO serialized_data(key, serialized) VALUES ('picstorage','". $savetodb ."')"; ?> Thanks, Kate Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/ Share on other sites More sharing options...
Stooney Posted June 22, 2008 Share Posted June 22, 2008 The syntax looks correct to me. You could try adding a space after 'serialized_data'. so.. <?php $query = "INSERT INTO serialized_data (key, serialized) VALUES ('picstorage','". $savetodb ."')"; ?> Also make sure the field in the database if of a type capable of storing what you are trying to store. And try to include any error messages you are getting. Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571284 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Share Posted June 22, 2008 you have to specify a table or a row, I'm a little rusty at database queries. Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571286 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Share Posted June 22, 2008 Secondly try no spaces between periods and var. Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571291 Share on other sites More sharing options...
kate_rose Posted June 22, 2008 Author Share Posted June 22, 2008 Here is the code at least the part I am having trouble with. <?php $savetodb = (serialize($picstorage)); //convert picstorage into a sqlinput string echo $savetodb; $query = "INSERT INTO serialized_data (key, serialized) VALUES ('picstorage','". $savetodb ."')"; mysql_query($query); ?> As far as i know the "serialized_data" part of the query is the part of the INSERT command which tells mysql which table to use. The database column is set to mediumtext but this is a rather big array. I will try setting it to accept larger strings. Anyway I am getting no error message at all. It all looks fine but when I go look in the serialized_data table nothing has been added. The echo $savetodb is returning the serialized array with no problem so it has to be in the query I think. k- ??? The string I am saving does have backslashes & stuff in it. Would that make a difference? Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571301 Share on other sites More sharing options...
Stooney Posted June 22, 2008 Share Posted June 22, 2008 Try this: mysql_query($query) OR die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571305 Share on other sites More sharing options...
kate_rose Posted June 22, 2008 Author Share Posted June 22, 2008 Oh thats handy. Sorry I didn't know about that before. The error I get is 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 'key, serialized) VALUES ('picstorage','a:308:{i:0;s:36:"Acanthaceae\Asystasia_ga' at line 1 Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571309 Share on other sites More sharing options...
Stooney Posted June 22, 2008 Share Posted June 22, 2008 Throw some backdrops around 'key'. (` = backdrop) $query = "INSERT INTO serialized_data (`key`, serialized) VALUES ('picstorage','". $savetodb ."')"; Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571313 Share on other sites More sharing options...
kate_rose Posted June 22, 2008 Author Share Posted June 22, 2008 That did it Chris. Thank you. Is key a reserved word or something?? What do the backdrops do? Thanks, Kate Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571315 Share on other sites More sharing options...
Stooney Posted June 22, 2008 Share Posted June 22, 2008 key is used by mysql. The backdrops basically just take whatever is inside them and doesn't check them for reserved mysql words. (That was probably worded terribly, but it's on the right track). Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571318 Share on other sites More sharing options...
kate_rose Posted June 22, 2008 Author Share Posted June 22, 2008 Thank you again. Chris. Link to comment https://forums.phpfreaks.com/topic/111297-solved-debugging-script-syntax-confusion/#findComment-571325 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.