Should I use get parameters or should I query again when moving from one page to other If the parameters change dynamically from one page to other?
Take an example.
I have two pages www.example.com
and www.example.com?a=
.
In the second page a value changes depending on user choice.'a' is a field in database say quantity of books in online book store
In the first page say a=2
at some point of time and at this point of time first user moves to second page and stays there for some point of time.In the mean time second user visits the second page and the a value changes to say a=0
. And now for the first user will the a value be 2 got from the get parameter or 0.
My question is if we use get parameters a
value may be wrong.
<?php
session_start();
include('connection.php');
$quant=isset($_GET['quant'])?$_GET['quant']:NULL;
$cod=isset($_GET['cod'])?$_GET['cod']:NULL;
if($cod!=NULL){
?>
<form name="select" action="block.php" method="get">
<p>Enter number of books you want to block</p> <br/>
<input type="textbox" name="quant"><br/>
<input type="hidden" name="cod" value="<?php echo "$cod"; ?>">
<input type="submit" name="submit" value="submit">
</form>
<?php
}
else{
$qry="select * from books where category='ncert' and quantity>0 ";
$books=mysqli_query($con,$qry);
$numrows=mysqli_num_rows($books);
if($numrows>0){
while($row=mysqli_fetch_assoc($books)){
$quantity=$row['quantity'];
echo "$quantity";
?>
<a href="example.php?<?php echo "$cod";?> example </a>
<?php
}
}
}
?>
Block.php
<?php
session_start();
include('connection.php');
$quant1=isset($_GET['quant'])?$_GET['quant']:NULL;
$cod1=isset($_GET['cod'])?$_GET['cod']:NULL;
$qry="select * from books where code='$cod1' ";
$quantity=$row['quantity'];// **This is the quantity I am talking about**
if($quantity>=$quant1&&$quant1>0){
// user buys quant1 amount of books
}
?>
Correct me if I am wrong