I'm trying to submit an array data from my form, but before submission I want that array value to be compared with the value I have from the database. if one among the value in the array is greater than the one I have in the database loop should be terminated and print the output otherwise the form should be submitted.
But the problem is both if and else and are tested and both of them executed.
MY FORM INPUT user Form
MY PHP CODE
if(isset($_POST['btn_action'])){
$material_id = $_POST['material_added_id'];
$material_issued = $_POST['material_isseud_weight']; //userInput--Array
$unit_type = $_POST['unit_type'];
$product_id = $_POST['product_id'];
$ricip_name = $_POST['ric'];
$count = 0;
for($count; $count < count($material_id); $count++) {
//fetching data from DB
$qry = "SELECT * FROM material_added_tb WHERE material_added_id = $material_id[$count]";
$statement = $conn->prepare($qry);
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $value) {
$material_weight = $value['material_weight'];
$material_name = $value['material_added_name'];
}
//compare the userArray data with the data from DB
if($material_issued[$count] > $material_weight) {
?>
<script>
alert('<?php echo $material_name . " is Out of Stock " ?>');
// window.location.href="../manufacture.php";
</script>
<?php
} else {
echo "submit the form";
}
}
}