Hello,
Have the following form that takes data from the DB when u click on the text the left input increments when u click on it the same input decrement its value.
Have 2 main issues now:
1- the value of the input fields needs to be set after the post is submitted and having issue with that since it's an array.
2-after the submit the post is saved in an array (the out is showing in the attched image), need to choose each related item , price and quantity like product 1 price 1 quantity 1 so i can update the db later on.
All the Best
<form method='POST' action=''>
<?php
if ($err1==0) {
/*DB CODES...*/
$num_rows = mysqli_num_rows($sql_1);
if (isset($_POST["form_Order"]) && $_POST["form_Order"] == "form_Order") {
$orderID=clean_input($_POST["orderID"]);
$cat_Code=$_POST["cat_Code"];
$sub_Cat_Code=$_POST["sub_Cat_Code"];
$array_Order = array($_POST);
print_r ($array_Order)."<br>";
/*DB CODES...*/
$res_sql_1 = mysqli_query($connection, $sql_2);
/*additional codes*/
}//end if $_POST
while ($row_sql_Item = mysqli_fetch_assoc($res_sql_Item)) {
$product_Name = $row_sql_Item["item"];
$product_Price = $row_sql_Item["price"];
$subCatCode=$row_sql_Item["sub_cat_code"];
if(isset($_POST['productName[]'])){ $productname=$_POST['productName[]'];}else{ $productname=$product_Name;}
if(isset($_POST['product_Price[]'])){ $productPrice=$_POST['product_Price[]'];}else{ $productPrice=$product_Price;}
echo "<div>
<input type='number' min='0' max='10' name='quantity[]' value='";
if(isset($_POST['quantity']) && is_array($_POST['quantity'])){
$quantitiez = array();
foreach ($quantitiez as $quant){
print $quant;
}
}else{ echo "0";}
echo "' onclick=\"this.parentNode.querySelector('input[type=number]').stepDown();this.form.submit();\" class='productQuantity' readonly>
<input type='text' min='0' max='10' name='productName[]' value='$productname' onclick=\"this.parentNode.querySelector('input[type=number]').stepUp();this.form.submit();\" class='productName' readonly>
<input type='text' name='product_Price[]' value='$productPrice' class='productPrice' onclick=\"this.form.submit()\" readonly>
<input type='hidden' name='orderID' value='$orderID'>
<input type='hidden' name='cat_Code' value='$catCode'>
<input type='hidden' name='sub_Cat_Code' value='$subCatCode'>
<input type='hidden' name='form_Order' value='form_Order'></div>
";
}//end While
}//end if $err1
?>
</form>