trampolinejoe Posted November 22, 2008 Share Posted November 22, 2008 Hello Guys, I need help, I am still abit of a newbie at all this, I have a multi select box thats actually created in php and fills up from the db ( i used a example i found online to make this) echo" <select name='product' id='product' size='5' tabindex='11' class='validate required product productMsg' multiple>"; //start the select box $results= mysql_query("SELECT ID, name FROM Products ORDER BY ID asc",$connection); $id = "ID"; $idname = "Name"; echo mysql_error(); if (mysql_Numrows($results)>0) //if there are records in the fields { $numrows=mysql_NumRows($results); //count them $x=0; while ($x<$numrows){ //loop through the records $theId=mysql_result($results,$x,$id); //place each record in the variable everytime we loop $theName=mysql_result($results,$x,$idname); echo "<option value=\"$theId\">$theName</option>\n"; //and place it in the select $x++; } } echo "</select>"; //close the select anyways we end up with something such as this: <select name='product' id='product' size='5' tabindex='11' class='validate required product productMsg' multiple> <option value="150">sampleProduct</option> <option value="151">10 Ft Trampoline</option> </select> which is great, but the thing is, i need to be able to select more then one item then post it to the DB. currently if I post a 2 selected items only 1 manages to actually get posted. I am guessing i need some kind of array to post the multiple values with, but to be honest I have no idea what to do? / how to do it? Can anybody please help me? cheers. Link to comment https://forums.phpfreaks.com/topic/133740-solved-multi-select-post-to-db/ Share on other sites More sharing options...
.josh Posted November 22, 2008 Share Posted November 22, 2008 change the name attribute to name='product[]' you can then access it from $_POST['product'][0] $_POST['product'][1] etc... Link to comment https://forums.phpfreaks.com/topic/133740-solved-multi-select-post-to-db/#findComment-696008 Share on other sites More sharing options...
trampolinejoe Posted November 22, 2008 Author Share Posted November 22, 2008 Thanks man that totally helped, Link to comment https://forums.phpfreaks.com/topic/133740-solved-multi-select-post-to-db/#findComment-696096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.