nz4y45 Posted February 17, 2009 Share Posted February 17, 2009 Hello, I have the following code, I would like to be able to capture each individual checkbox that is selected, as of right now, only the first is captured because the checkboxes have the same "name". Thanks for any help! $link = mysql_connect('host', 'id, 'pw); mysql_select_db('db', $link); $sql = "select * from ChangeControl order by Client, SDate"; $result = mysql_query($sql); $tdcount = 1; $numtd = 1; // number of cells per row echo "<form action=\"CC_test.php\">"; echo "<table border='1'>"; while($row = mysql_fetch_array($result)) { if ($tdcount == 1) echo "<tr>"; if (stristr ($row[8], "Yes")) $status='Closed'; else $status='Open'; echo "<td><input type=\"checkbox\" name=\"checkbox\" value='$row[1]'><b>Ticket #:</b> $row[1] <b>Client:</b> $row[6] <b>Start Date:</b> $row[2] <b>End Date:</b> $row[3]<br><b>Description:</b> $row[7]"; // display as you like if ($tdcount == $numtd) { echo "</tr>"; $tdcount = 1; } else { $tdcount++; } } // time to close up our table if ($tdcount!= 1) { while ($tdcount <= $numtd) { echo "<td> </td>"; $tdcount++; } echo "</tr>"; } echo "</table>"; echo "<input type=\"submit\" name=\"submit\" value=\"Send Daily Report\">"; echo "</form>"; Quote Link to comment https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/ Share on other sites More sharing options...
sasa Posted February 17, 2009 Share Posted February 17, 2009 change name from checkbox to checkbox[] Quote Link to comment https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/#findComment-764178 Share on other sites More sharing options...
nz4y45 Posted February 17, 2009 Author Share Posted February 17, 2009 wow - so easy. Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/#findComment-764235 Share on other sites More sharing options...
nz4y45 Posted February 17, 2009 Author Share Posted February 17, 2009 So, I think I'm having some of the same problems as others with Arrays. I have my array now, and I can print it out on screen, but I would like to store the data in seperate rows in my database? I have tried numerous things, and I can get only the last checkbox selected to enter? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/#findComment-764456 Share on other sites More sharing options...
sasa Posted February 17, 2009 Share Posted February 17, 2009 can you post code Quote Link to comment https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/#findComment-764520 Share on other sites More sharing options...
nz4y45 Posted February 18, 2009 Author Share Posted February 18, 2009 This is how i'm gathering the data: $link = mysql_connect('host', 'id, 'pw); mysql_select_db('db', $link); $sql = "select * from ChangeControl order by Client, SDate"; $result = mysql_query($sql); $tdcount = 1; $numtd = 1; // number of cells per row echo "<form action=\"CC_test.php\">"; echo "<table border='1'>"; while($row = mysql_fetch_array($result)) { if ($tdcount == 1) echo "<tr>"; if (stristr ($row[8], "Yes")) $status='Closed'; else $status='Open'; echo "<td><input type=\"checkbox\" name=\"checkbox\" value='$row[1]'><b>Ticket #:</b> $row[1] <b>Client:</b> $row[6] <b>Start Date:</b> $row[2] <b>End Date:</b> $row[3]<br><b>Description:</b> $row[7]"; // display as you like if ($tdcount == $numtd) { echo "</tr>"; $tdcount = 1; } else { $tdcount++; } } // time to close up our table if ($tdcount!= 1) { while ($tdcount <= $numtd) { echo "<td> </td>"; $tdcount++; } echo "</tr>"; } echo "</table>"; echo "<input type=\"submit\" name=\"submit\" value=\"Send Daily Report\">"; echo "</form>"; This is how I print out the array, <? if(isset($_POST['checkbox'])) { print '<pre>'; // print_r($_POST['checkbox']); // print '</pre>'; print 'Send daily reports for the following change records?: '; echo "<br>"; // You wanted to loop. foreach($_POST['checkbox'] as $value) { // print $value . ' ,'; echo $value."<br>"; } } ?> Now, I just need to be able to seperate the array values into seperate database rows. Quote Link to comment https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/#findComment-765199 Share on other sites More sharing options...
sasa Posted February 18, 2009 Share Posted February 18, 2009 1st change name from checkbox to checkbox[] 2nd in CC_test.php ... foreach($_POST['checkbox'] as $value){ //insert data in database, in variable $value is value of checked checkbox ($row[1] from 1st database) ... Quote Link to comment https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/#findComment-765427 Share on other sites More sharing options...
nz4y45 Posted February 24, 2009 Author Share Posted February 24, 2009 I have the code you listed in your reply, it still doesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/#findComment-770085 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.