project3 Posted February 27, 2008 Share Posted February 27, 2008 Ok I have a multiple select box and want to insert the results into the db. right now it only inserts the last selected option. Im sure I need to turn that into an array and get it like this $theval[0]; $theval[1]; but I'm not sure how you would know how many values are in the array. then how would i insert that into the db all in the same field. Quote Link to comment Share on other sites More sharing options...
fnairb Posted February 27, 2008 Share Posted February 27, 2008 You could implode the array on insert then explode it when reading the value. I like pipe '|' since you hardly ever use it but there is no magic reason I chose it. <?php $insval = implode('|', $theval); // do insert using $insval // get back to the array $theval = explode('|', $row['theval']); ?> Quote Link to comment Share on other sites More sharing options...
poirot Posted February 27, 2008 Share Posted February 27, 2008 How is the HTML code with the checkboxes anyways? Remember that you need to send it as an array to ensure PHP can get all your selections. Then you can use a loop (like foreach) to work with the items and insert them into the database. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 27, 2008 Share Posted February 27, 2008 The name of the box needs to have [] after it. That will give you your array. Then use implode. Quote Link to comment Share on other sites More sharing options...
project3 Posted February 27, 2008 Author Share Posted February 27, 2008 I had [] in it. I solved the problem by using count to count the number of objects in array then inserting in db. Quote Link to comment 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.