douyi1963 2016-04-09 14:42 采纳率: 0%
浏览 11

使用get参数是否始终给出正确的答案?

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看