How To Insert Data From Checkbox
Posted: Sat Apr 19, 2008 6:51 am
heLLooo..i'm doing a system that will auto assign a person to a company based on state...i will choose few person using a checkbox that hold the id and insert the data based on the state..for example there's 4 company in the same state and i want to assign 2 person..the problem is that i cant find a solution on how to assign the 2 person into 4 places..the codes below will only assign 1 person as it will took the last data from the array..could anyone give me the logic or ideas for this??....
<td bgcolor=lightblue align="center"><input name="checkbox[]" type="checkbox" value="$log_id" checked)/></td>
******************************************************************************************
if(isset($_POST['checkbox']))
{
$checkbox = $_POST['checkbox'];
$n = count($checkbox);
$i = 0;
while ($i < $n)
{
echo "<center><li>$checkbox[$i]</li> \r\n</center>";
$check=$checkbox[$i];
$i++;
$query = "UPDATE auto_assign SET lect_id='$check' WHERE co_state='$co_state'";
mysql_query($query) or die('Error, query failed');
}
echo "</ol></tr></td>";
*****************************************************************************************
the database....(supposed it will insert the id into the data)
id co_name co_state
0 Fellisa Co Jordan
0 Mine Jordan
0 Abraham co Egypt
0 Dancom Jordan
0 Wowo Co Andala
0 Marcom Andala
<td bgcolor=lightblue align="center"><input name="checkbox[]" type="checkbox" value="$log_id" checked)/></td>
******************************************************************************************
if(isset($_POST['checkbox']))
{
$checkbox = $_POST['checkbox'];
$n = count($checkbox);
$i = 0;
while ($i < $n)
{
echo "<center><li>$checkbox[$i]</li> \r\n</center>";
$check=$checkbox[$i];
$i++;
$query = "UPDATE auto_assign SET lect_id='$check' WHERE co_state='$co_state'";
mysql_query($query) or die('Error, query failed');
}
echo "</ol></tr></td>";
*****************************************************************************************
the database....(supposed it will insert the id into the data)
id co_name co_state
0 Fellisa Co Jordan
0 Mine Jordan
0 Abraham co Egypt
0 Dancom Jordan
0 Wowo Co Andala
0 Marcom Andala