jeudi 26 mars 2015

how to insert textfield just the checked only to database? [on hold]

I have form like this



<form method="post" action="function.php">
<input type="text" name="pcs[]" value="<?php echo $data['pcs']; ?>">Pcs
<input type="checkbox" name="id[]" value="<?php echo $data['id']; ?>">
</form>


i have two tables in my databse, i want insert my second db with the first value db, but i just want insert the value with the new value from the textfield was im checked.


and i have insert funtion page like this...



<?php
include('connect.php'); //connect database

$id= $_POST['id'];
$pcs= $_POST['pcs'];
$pcscount=count($id); //count the checked
if (empty($pcscount))

{
echo"<script>alert('Sorry, at least Choose 1');document.location='order.php';
</script>";
break;
} // must checked at least 1 checkbox

for($no=0;$no<$pcscount;$no++) {

$pcs[$no] = mysql_real_escape_string($pcs[$no]);

if (!empty($id[$no])){ //just process the checked pcs

$sql= mysql_query("select * from product_order where id='$id[$no]'") or die(mysql_error());
$row = mysql_fetch_array($sql);
$query = mysql_query("insert into product_checkout set id='$row[id]', name='$row[name]', price='$row[price]', pcs='$pcs[$no]'") or die(mysql_error());
}
}

?>


I was try and modified that code, but the column pcs from product_checkout always insert from the first loop (function "for" loop), event the checkbox unchecked...


what variable must im insert to column "pcs" on product_checkout table if i want just the checked only value...


some one help me please, im so confused...tq





Aucun commentaire:

Enregistrer un commentaire