In a single product page, the product ID is assigned to the var $productID
. The problem is when, staying in one of the fields of the form and push the ENTER key, the page crashes since the script can't find the ID again. So I would implement the script in the following way.
<?php
$product_id = $_GET['product_id'];
include '../sys/conn.php';
$risultato = mysqli_query ($conn, "
(mysql query)
") or die ("Query not valid: " . mysqli_error($conn));
mysqli_close($conn);
$row = mysqli_fetch_array($risultato);
?>
That I implemented in order that if $_GET is not set properly, it is set to 13321 (example value).
<?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 ("Query not valid: " . mysqli_error($conn));
mysqli_close($conn);
$row = mysqli_fetch_array($risultato);
}
?>
The conditional clause looks like is not accepted and generates errors such like syntax or unexpected variables. Any help?
---VERSION 2----
<?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 ("Query non valida: " . mysqli_error($conn));
mysqli_close($conn);
$row = mysqli_fetch_array($risultato)
}
?>
And the error is: Parse error: syntax error, unexpected '}' in /Applications/XAMPP/xamppfiles/htdocs/gest/pages/singolo_prodotto.php on line 66
You missed bracket:
if(!isset($_GET['product_id']){
Should be
if(!isset($_GET['product_id'])){