sylunt1 Posted January 16, 2008 Share Posted January 16, 2008 I have a form that has about 100 check boxes on it. 1 for each task id. What I want is to update a mysql db when you click submit. In other words... I want to take the boxes that are checked and enter that (the value will be 1 if checked) into the db according to the task id. How do I do this with the least effort (not defining each check with a different name staticly.) Currently I have : if ($tasks_id != $previous_tasks_id){ print '<table width="90%" cellspacing="3" cellpadding="3" border="0"><tr><td width="30%" height="1">' . $tasks_id . ' - ' . $tasks_task . '</td><td halign="left" width="30%" height="1"><INPUT TYPE=CHECKBOX NAME="' . $tasks_id . '"" VALUE="1""> complete</td></tr></table>'; $previous_tasks_id = $tasks_id ; } but Im not sure where to go from here. any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/ Share on other sites More sharing options...
cooldude832 Posted January 16, 2008 Share Posted January 16, 2008 show your form a bit better. if they are just mysql bool type fields you can probably do something simple, so show us the form and the mysql table. Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-441262 Share on other sites More sharing options...
nikefido Posted January 16, 2008 Share Posted January 16, 2008 and use [ code] tags, plz (and/or [ php][/code] tags) Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-441264 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 And that does what? Ah adds color. please (and/or [ php][/code] tags) Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-441304 Share on other sites More sharing options...
sylunt1 Posted January 16, 2008 Author Share Posted January 16, 2008 <FORM ACTION="tsecomplete.php"> <blockquote> <?php $db = mysql_connect("$server", "$user", "$password"); mysql_select_db('mentor', $db) or die ('Cannot connect to $db_Database : ' . mysql_error()); $id = $_GET['id']; $result = mysql_query ("SELECT tse.tse_id, tse.tse_name, tasks.tasks_id, tasks.tasks_task, tasks.tasks_week, tasks.tasks_day, tasks.tasks_order FROM tse, tasks WHERE tse.tse_id = $id ORDER BY tasks.tasks_week, tasks.tasks_day, tasks.tasks_order") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $tasksans_id = $row['tasksans_id']; $tasks_tsedone = $row['tasks_tsedone']; $tasks_date = $row['tasks_date']; $tasks_mdone = $row['tasks_mdone']; $tasks_id = $row['tasks_id']; $tasks_task = $row['tasks_task']; $tasks_week = $row['tasks_week']; $tasks_day = $row['tasks_day']; $tasks_order = $row['tasks_order']; $tasks_add1 = $row['tasks_add1']; $tasks_add2 = $row['tasks_add2']; $tasks_add3 = $row['tasks_add3']; $tasks_add4 = $row['tasks_add4']; $tse_id = $row['tse_id']; $tse_name = $row['tse_name']; $tse_weekorder = $row['tse_weekorder']; $weeks_id = $row['weeks_id']; $weeks_1 = $row['weeks_1']; $weeks_2 = $row['weeks_2']; $weeks_3 = $row['weeks_3']; $weeks_4 = $row['weeks_4']; if($count==0){ print'<br /><br /><center><b>TSE '.$tse_name.'</b></center>'; $count=1; } if ($tasks_week != $previous_tasks_week){ print '<br /><H3>Week ' . $tasks_week . '</H3><br />'; $previous_tasks_week = $tasks_week ; } if ($tasks_day != $previous_tasks_day){ print '<br /><b>Day ' . $tasks_day . '</b><br /><br />'; $previous_tasks_day = $tasks_day ; } if ($tasks_id != $previous_tasks_id){ print '<table width="90%" cellspacing="3" cellpadding="3" border="0"><tr><td width="30%" height="1">' . $tasks_id . ' - ' . $tasks_task . '</td><td halign="left" width="30%" height="1"><INPUT TYPE=CHECKBOX NAME="' . $tasks_id . '"" VALUE="1""> complete</td></tr></table>'; $previous_tasks_id = $tasks_id ; } } ?> <br /><br /> <INPUT TYPE=SUBMIT VALUE="submit"> </FORM> </blockquote> <br /><br /> </BODY> </HTML> what is supposed to happen.... each task has an id (task_id) anything that is checked i want to update the status in the db from a 0 to a 1. So the question is this... since every item is task_id how do I update multiple tasks to status 1? Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-441328 Share on other sites More sharing options...
sylunt1 Posted February 2, 2008 Author Share Posted February 2, 2008 any further thoughts on this? Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-455914 Share on other sites More sharing options...
mmarif4u Posted February 2, 2008 Share Posted February 2, 2008 You want to update a specific row in a db for task_id. Am i right. Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-455919 Share on other sites More sharing options...
laffin Posted February 2, 2008 Share Posted February 2, 2008 WHERE task_id IN (x,y,z) u put use the IN function which works like an OR operator UPDATE tasks SET status=1 WHERE task_id=x OR task_id=y OR task_id=z Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-455930 Share on other sites More sharing options...
sylunt1 Posted February 4, 2008 Author Share Posted February 4, 2008 there is a row called task_complete or something of that nature... it defaults to 0 (not done) when they user puts a check in the box next to the tasks then it will update the row with a 1. What I am thinking is what laffin wrote - but I dont know how to pass all the variables like that - if they check # 1, 6, 47 how do I pass task_id=1, task_id=6 and task_id=47 from the form to the processing page? I think I am to the point where I confused myself as to wtf is going on Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-458011 Share on other sites More sharing options...
laffin Posted February 5, 2008 Share Posted February 5, 2008 now i had some code somewhere around in here, that shows how checkboxex worked with php, note that ceckboxes not marked are not sent, otherwise the value is sent. so will expand a little to show how to build a WHERE query with multiple cb <?php $where=""; if($_SERVER['REQUEST_METHOD']=='POST') { if(isset($_POST['cb'])) { $cbv=$_POST['cb']; $where = " WHERE task_id IN (" . implode(',',$cbv) . ")"; } echo "where = '$where'"; } ?> <html> <body> <form method="POST"> <INPUT TYPE='checkbox' name='cb[]' value='0'> <INPUT TYPE='checkbox' name='cb[]' value='1'> <INPUT TYPE='checkbox' name='cb[]' value='2'> <INPUT TYPE='checkbox' name='cb[]' value='3'> <INPUT TYPE='checkbox' name='cb[]' value='4'> <INPUT type="submit"> </FORM> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/#findComment-458176 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.