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. Quote 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. Quote 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.")"; Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.