In my project I have:
- products list page
- single product page
Each row in the products list have a link that passes the product_ID to the single product page as follows:
<!---Products List Page--->
....
<td>
<a href="singolo_prodotto.php?product_id='.$row['id'].'">Link</a>
</td>
In the single product page, the product_id is catched as follows:
<!---Single Product--->
<!DOCTYPE html>
<?php
$product_id = $_GET['product_id'];
if(!isset($_GET['product_id'])){$product_id='13321';}
else {
include '../sys/conn.php';
$risultato = mysqli_query ($conn, "
(*...mysql query...*)
") or die ("Invalid query: " . mysqli_error($conn));
mysqli_close($conn);
$row = mysqli_fetch_array($risultato);
}
?>
In each field, the array value is embedded as follows:
<div class="col-lg-3">
<form role="form">
<div class="form-group">
<label>SKU</label>
<input class="form-control" placeholder="SKU Code" value = "<?php echo $row['6']; ?>" >
</div>
</form>
</div>
If I pass from the products lists to the single product page through the above mentioned link, everything works fine. Reloading the single product page everything works fine as well. But if I push the ENTER key being positioned in one of the fields of the "single product" page it crashes giving these errors:
Notice: Undefined index: product_id in /Applications/XAMPP/xamppfiles/htdocs/gest/pages/singolo_prodotto.php on line 6
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/gest/pages/singolo_prodotto.php on line 637
Any idea on how this issue can be fixed?