sabinmash Posted October 31, 2011 Share Posted October 31, 2011 I have tried many ways of storing an array of data that comes from a multiple selection form into a mysql table, including serialization. I am currently trying to do it by forming a string, and using the string in the insert query, but keep getting errors, or just nothing happening. I am not sure what I am doing wrong. $categoryString = array(); if ($categoryArray){ foreach ($categoryArray as $category){ $categoryString[] = $category.'<br />';} } $categoryquery= "INSERT INTO categoryname VALUES('$categoryString')"; mysql_query($categoryquery); Thank you for your time as always. Link to comment https://forums.phpfreaks.com/topic/250186-cant-insert-array-into-mysql-query/ Share on other sites More sharing options...
manohoo Posted October 31, 2011 Share Posted October 31, 2011 Do a var_dump($categoryquery) right before executing the query and you will find out why. Link to comment https://forums.phpfreaks.com/topic/250186-cant-insert-array-into-mysql-query/#findComment-1283788 Share on other sites More sharing options...
sabinmash Posted October 31, 2011 Author Share Posted October 31, 2011 Ah silly me, didn't even name the table. I have what seems like the right syntax now. I can echo out what looks like the correct VALUES syntax, that should be going into the db, but still nothing happens. If I take away the concatenation of the string, inside the values parameters, I just get a database category name with 4 words in it, inside of having them each in their own cell. if ($categoryArray){ foreach ($categoryArray as $category){ $categoryString .= "'$".$category."',"; } } echo $categoryString; $categoryquery = "INSERT INTO category (categoryname) VALUES(".$categoryString.")"; Link to comment https://forums.phpfreaks.com/topic/250186-cant-insert-array-into-mysql-query/#findComment-1283798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.