I try to keep the data and insert into sql when row selected by checkbox from datalist table after user push Submit button
Checkbox Conditions
$CheckBox = $_POST["dataset"];
if(isset($_POST["Submit"]))
{
if(empty($CheckBox) || $CheckBox == 0 ) {
echo "Please select data after click submit !!";
}else{
foreach($_POST["dataset"] as $i)
{
$query = "INSERT INTO r (id,accountcode,orders)
VALUES('{$_POST['txtID'][$i]}','{$_POST['txtACC'][$i]}','{$_POST['txtITM'][$i]}')";
$Q_INSERT = mysqli_query($conn,$query);
}
}
if($Q_INSERT)
{
echo "<script> alert('SUCCESS !')</script>";
}
}
datalist table
$i=0;
while($i<$numr && $ven2 = $ven->fetch_assoc())
{
?>
<tr>
<td><center><input type="hidden" name="txtID[]" id="txtID" value="<?php echo $ven2["id"];?>"><?php echo $ven2["id"];?></center></td>
<td><center><input type="hidden" name="txtACC[]" id="txtACC" value="<?php echo $ven2["acc_name"];?>"><?php echo $ven2["acc_name"];?></center></td>
<td><input type="hidden" name="txtITM[]" id="txtITM" value="<?php echo $ven2["item_name"];?>"><?php echo $ven2["item_name"];?></td>
<td><center><input type="checkbox" name="dataset[]" id="dataset" value="<?php echo $i++; ?>" ></center></td>
</tr>
Aucun commentaire:
Enregistrer un commentaire