hi every body, i am sure its not that much hard but somehow i stuck in situation which look
very much unclear to me.

in fact i have a table through i am selecting different records

each records will be printed with the checkbox


what i want to insert checked fields in the database

following is the code which i am using for printing the each field with check box

<?
   $con = mysql_connect("localhost","","");
   if(!$con)
     {
     die('Could not connect: ' . mysql_error());
    }
   mysql_select_db("", $con);

	$result= mysql_query("SELECT * FROM central  ");
	
	while($row = mysql_fetch_array($result))
  {
  echo "<table width=100% bgcolor=#ffffff >";
echo "<form method=post name=myform action=wh_request_test.php>";
echo  "<tr>";
 echo   "<td align=center>" .$row[1] . "</td>";
  echo  "<td align=center>" . $row[2] . "</td>";
 echo   "<td align=center>" . $row[5] . "</td>";
 echo   "<td align=center>" . $row[4] . "</td>";
   
echo	"<td><input type=checkbox name=cc[] vlaue= $row[0] /> </td>";
  echo "</tr>";
 echo 	"</table>"; 

     }
	
    ?>

I have some doubt

Exactly what do you want?

Do you have column for checkbox say yes/no or 0/1 in central table ?

If user checks the check box of some row, then submits the form what you want to do?

do you want to reflect check values in database when user open abouve page?

Please clearify.

I assume following code will work for you. Place this code in your action file where you are updating your database.

$keylist="";
	foreach ($_POST['cc'] as $key => $value) 
	{
	    if($i==0)		 
	 		$keylist.=$key;
	    else
			$keylist.=",".$key;
		$i++;
	}	

	$updquery="update central set checkcolname='Y' where keycolumnname in ($keylist)";

//	exeucte_update_query($updquery); use proper syntax

Thanks First of all appreciate your help.
in fact i have table which contain the quantity of items(from which i am selecting with checkbox) what i just want to insert checked rows in an other table and delete from parent table so i could keep the status of quantity updated.
for this purpose i am able to build a rough code but not working.

$result=mysql_query("Select * From $request Where ItemDesc='$item_name'");

while($row=mysql_fetch_array($result))
{
 echo "<tr bgcolor=#FFFFFF style=color:#000000;>";  

echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[5] . "</td>";
echo "<td>" . $row[6] . "</td>";
echo "<td>" . $row[7] . "</td>";
echo "<td>" . $row[8] . "</td>";
echo "<td><input name=id[] type=checkbox value=$row[4] /> </td>";
echo      "</tr>";




}

#
if(isset($_POST['Build'])){
#
//new code sent from form
#

#

foreach($_POST['id'] as $tablename_value) {
#
$query = "insert into detailed (name,qty) values ('$wow','$tablename_value')";
                      }

}

?>

i above code i am not able to figure it out whether i have to keep foreach loop in while loop or out of while loop so i could get the value of each cell.
please give some suggestion

You are passing only quantity in value tag of check box. for deleting and inserting you need to have some primary key information in value of checkbox. post[id] array will contain only checked rows. you must set value of checkbox in following manner value = '{$row[0]},$row[4]' . I am assuming row[0] contains primary key of table.

I have given you the foreach loop for updating the table, now you can use same loop for both insertion and deletion. foreach loop will work independtly no need to keep it in while loop
following code should be kept in action page of your form.

$keylist="";	
foreach ($_POST['id'] as $tablename_value) 	
{	    
 	$arr=split(",",$tablename_value);
 	//$arr[0] is primary key $ROW[0]
 	//$arr[1] is quantity value $ROW[4]
 	$deletequery="DELETE FROM TABLE1 WHERE PKCOLUMN='{$arr[0]}'";
 	$insertquery="insert into table2 (pkcol,quantitycol) values('{$arr[0]}','{$arr[1]}')";
}

Thanks genius, for giving your precious time. It helped me lot
and if you don't mind can you suggest me any tutorial regarding the issue discussed, for future reference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.