roobon Posted August 6, 2007 Share Posted August 6, 2007 I have a dynamic category list, I have printed those list with check box in the form. I have to check those boxes and submit. How can I pick all checked value in action page? Right now only one value passing from several check boxes while several check boxes checked. This is my form <form name="entryform" action="cat_sec_submit.php" method="post"> <? $row = mysql_fetch_object($result); echo $row->org_id . ', '; echo $row->org_name . '<br>'; ?> <? $query1 = "SELECT * FROM category"; $result1 = mysql_query($query1); ?> <? while ($row1 = mysql_fetch_object($result1)) {$cat = "$row1->cat_name"; $value = "$row1->value"; echo "<input name= \"cat_list\" type=\"checkbox\" name=\"checkbox\" value=\"$value\" />" . "$cat" ;} ?> <input type="submit" name="Submit" value="Submit" /> <input name="h1" type="hidden" id="h1" value="<?php echo $_GET['id'];?>"> </form> This is Action Page <? $id = $_POST['h1']; if($_POST['Submit']!="") {$query = ("insert into org_option (org_id, cat_list) values ('$id', '$_POST[cat_list]')"); $insert = mysql_query($query); echo "insert into org_option (org_id, cat_list) values ('$id', '$_POST[cat_list]')"; if ($insert) echo '<b>Sucessfully Added Organizaton Details</b> '; } Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/ Share on other sites More sharing options...
Barand Posted August 6, 2007 Share Posted August 6, 2007 echo "<input name= \"cat_list\" type=\"checkbox\" name=\"checkbox\" value=\"$value\" />" . "$cat" ;} So good they named it twice ! add [] to the name echo "<input name= \"cat_list[]\" type=\"checkbox\" value=\"$value\" />" . "$cat" ;} then foreach ($cat_list as $value) { //process value } Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-316600 Share on other sites More sharing options...
roobon Posted August 7, 2007 Author Share Posted August 7, 2007 Thanks for helping me. It is working. I need more help. I am trying to insert checked value into one field and in one record. But I failed. The status of my pages is: /*** Entry Form *****/ <form name="entryform" action="cat_sec_submit.php" method="post"> <? $row = mysql_fetch_object($result); echo $row->org_id . ', '; echo $row->org_name . '<br>'; ?> <? $query1 = "SELECT * FROM category"; $result1 = mysql_query($query1); ?> <? while ($row1 = mysql_fetch_object($result1)) {$cat = "$row1->cat_name"; $value = "$row1->value"; echo "<input name= \"cat_list[]\" type=\"checkbox\" name=\"checkbox\" value=\"$value\">" . "$cat" ;} //echo "$row1->sec_list"; ?> <input type="submit" name="Submit" value="Submit" /> <input name="h1" type="hidden" id="h1" value="<?php echo $_GET['id'];?>"> </form> /**** Action Page ********/ <? $id = $_POST['h1']; $cat_list1 = $_POST[cat_list]; $value1 = $_POST[$value]; foreach ($cat_list1 as $value1) { echo $value1; } if($_POST['Submit']!="") {$insert = mysql_query("insert into org_option (org_id, cat_list) values ('$id', '$value1')"); if ($insert) echo '<b>Sucessfully Added Organizaton Details</b>'; } In addition I am sending my table snapshot by attached. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-317497 Share on other sites More sharing options...
Barand Posted August 7, 2007 Share Posted August 7, 2007 is this what you wanted? <?php /**** Action Page ********/ if (isset($_POST['Submit'])) { $id = $_POST['h1']; $cat_list1 = $_POST[cat_list]; $errors=0; foreach ($cat_list1 as $value1) { echo $value1; $insert = mysql_query("insert into org_option (org_id, cat_list) values ('$id', '$value1')"); if (!$insert) $errors++; } if (!$errors) echo 'Sucessfully Added Organizaton Details'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-317732 Share on other sites More sharing options...
roobon Posted August 8, 2007 Author Share Posted August 8, 2007 Thanks for your reply. Actually I wanted to insert all checked value in one field at a time. This is sample value e, p, n etc. When they are selected then I would like to insert them this way 'epn' Is this a way? I tried hard but don't understand which is the right way. Your help would be appreciated. - Roobon Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-318211 Share on other sites More sharing options...
chronister Posted August 8, 2007 Share Posted August 8, 2007 First, take a look at this line and tell me what is wrong with it. <?php echo "<input name= \"cat_list[]\" type=\"checkbox\" name=\"checkbox\" value=\"$value\">" . "$cat" ;} ?> There is a problem that will wreak havoc on you. Rather than tell you what it is, I wanna see if you can tell me Also, I find that escaping a shitload of quotes is too tedious. try it like this. <?php echo '<input name="cat_list[]" type="checkbox" name="checkbox" value="'.$value.'">'.$cat; ?> It is a lot cleaner and will help find errors (which I duplicated in my line of code ) Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-318226 Share on other sites More sharing options...
Barand Posted August 8, 2007 Share Posted August 8, 2007 <?php /**** Action Page ********/ if (isset($_POST['Submit'])) { $id = $_POST['h1']; $cat_list1 = $_POST[cat_list]; $value1 = join('', $cat_list); echo $value1; $insert = mysql_query("insert into org_option (org_id, cat_list) values ('$id', '$value1')"); if ($insert) echo 'Sucessfully Added Organizaton Details'; } ?> [ However, if you are going to need to query the org_id tables and category tables together I'd reccomend the separate records approach. (google 'data normalization ') Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-318228 Share on other sites More sharing options...
Barand Posted August 8, 2007 Share Posted August 8, 2007 Chronister, The double name was pointed out a couple of days ago Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-318232 Share on other sites More sharing options...
chronister Posted August 8, 2007 Share Posted August 8, 2007 hehehe, sorry thats what I get for trying to help with this stuff at 2 in the morning..... DUH!!!!!! thanks Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-318235 Share on other sites More sharing options...
roobon Posted August 13, 2007 Author Share Posted August 13, 2007 Thanks for your recommendation. :) First, take a look at this line and tell me what is wrong with it. <?php echo "<input name= \"cat_list[]\" type=\"checkbox\" name=\"checkbox\" value=\"$value\">" . "$cat" ;} ?> There is a problem that will wreak havoc on you. Rather than tell you what it is, I wanna see if you can tell me Also, I find that escaping a shitload of quotes is too tedious. try it like this. <?php echo '<input name="cat_list[]" type="checkbox" name="checkbox" value="'.$value.'">'.$cat; ?> It is a lot cleaner and will help find errors (which I duplicated in my line of code ) Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-322226 Share on other sites More sharing options...
roobon Posted August 13, 2007 Author Share Posted August 13, 2007 Excellent Suggestion. It is working. I am also keeping your recommendation in my mind. Thanks a lot for being with me. :) Roobon <?php /**** Action Page ********/ if (isset($_POST['Submit'])) { $id = $_POST['h1']; $cat_list1 = $_POST[cat_list]; $value1 = join('', $cat_list); echo $value1; $insert = mysql_query("insert into org_option (org_id, cat_list) values ('$id', '$value1')"); if ($insert) echo 'Sucessfully Added Organizaton Details'; } ?> [ However, if you are going to need to query the org_id tables and category tables together I'd reccomend the separate records approach. (google 'data normalization ') Quote Link to comment https://forums.phpfreaks.com/topic/63513-how-can-i-pick-all-checked-value-in-action-page/#findComment-322227 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.