Forum Moderators: coopster
when i submit, input id is right, but input description is not following the id
here the code:
<?php
// conect to database & tabel here//process input form
if(isset($_POST[op])== "1"){
$item = $_POST['id'];
$description = $_POST['description'];
$num = count($item);
$numb = $num-1;
for ($i=0; $i<=$numb; $i++)
{
$items = $item[$i];
$desc = $description[$i];
$query = "INSERT INTO tablename (ItemNo, Description)
VALUES ('$items','$desc')";
mysql_query($query) or die(mysql_error());
}
} else {
?>
<form name="input" method="post" action="">
<input type="hidden" name="op" value="1" />
<table width="337">
<th width="91"><div align="left">Item</div></th>
<th width="234"><div align="left">Description</div></th>
<?
$number = 3;
for ($i=1; $i<=$number; $i++)
{?>
<tr>
<td><input type="checkbox" name="id[]" value="red<?=$i?>" />product<?=$i?></td>
<td> <input type="text" name="description[]" size="10" value="description-<?=$i?>"> </td>
</tr>
<?php }
?>
</table>
<input type="submit" name="submit" value="Submit">
</form>
<?php }?>
thanks for your help
(number 1,2,3 is checkbox)
Item Description
1. product1 - Description1
2. product2 - Description2
3. product3 - Description3
when we check 1 and 3, and then submit, its will save wrong data (not the right data that i want)
here the data save to table when we check 1 and 3:
ItemNo Description
--------------------------
product1 Description1
product3 Description2
see.. the product 3 description is not the right data, it should be Description3 not Description2
can you help me pls.
thanks
Note the changes:
$num = count($item);
for ($i=1; $i<=$num; $i++)
{
and on this block as well:
<td><input type="checkbox" name="id[<?=$i?>]" value="red<?=$i?>" />product<?=$i?></td>
<td> <input type="text" name="description[<?=$i?>]" size="10" value="description-<?=$i?>"> </td>
Habtom