Jump to content

Recommended Posts

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 . '&nbsp- ' . $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.

 

Link to comment
https://forums.phpfreaks.com/topic/86357-multiple-entries-from-a-form/
Share on other sites

<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 . '&nbsp- ' . $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?

  • 3 weeks later...

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 :)

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>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.