I'm trying to test whether a $_GET variable is set when a specific PHP page is visited:
I have a form which posts back to the same page (see below) below the form is PHP code to check whether the product_id
variable is set and performs actions accordingly.
FORM
<form action="form_update_products.php" method="post" name="search" id="search">
<table width="100%" cellspacing="0" cellpadding="2">
<tr>
<td colspan="2" class="text-18">
View / Update Product Barcodes by Product ID:
</td>
</tr>
<tr>
<td colspan="2" align="right">
<img src="images/spacer.png" width="100" height="4" />
</td>
</tr>
<tr>
<td width="12%" align="right">
<input name="product_id" type="text" class="size-box" id="product_id"
onclick="this.value = '';" style="font-size: 22px; width:500px"/>
</td>
<td width="88%">
<input name="submit" type="submit" class="submit-button"
id="submit" value="View Product Barcodes" />
</form>
form_update_products.php
<?php
$product_id=$_POST['product_id'];
header('Location: update_products.php?id='.$product_id.'');
?>
PHP
if (isset($_GET['id']))
{
$product_id = $_GET['id'];
}
if (!isset($product_id))
{
echo '';
}
else { // output something }
For some reason the $_GET['id']
variable always seems to default to the same product_id
and only changes when entering a different product_id
in the form. Even when closing the browser and opening the page afresh, the $_GET['id']
variable is set.
Can anybody tell me why the $_GET['id']
variable always seems to be set?