$ _POST变量是重复的

时间:2012-03-13 00:43:59

标签: php

我甚至不知道如何谷歌这个...想象它是愚蠢的......但任何帮助都会很棒......

在提交表单时传递变量...当回显$ _POST时它很好......但当我把它放入php变量时它是重复的

 <?

 //list transactions by month
 if ($_POST['m']=="yes"){
 $table = $_POST['month'];
 $_SESSION['table']=$_POST['month'];

 $conn = mysql_connect("localhost", "mss_records", "3205") or die(mysql_error());
 mysql_select_db('store_records', $conn) or die(mysql_error());

 $result = mysql_query("SELECT * FROM $table");

 while($row = mysql_fetch_array($result))
 {
 $id=$row['transaction'];
 $date=$row['date'];
 $time=$row['time'];
 $paid=$row['payment'];
 $total=$row['total'];
 echo '<style type="text/css">
 <!--
 .list {
 font-family: Georgia, "Times New Roman", Times, serif;
 font-size: 12px;
 color: #000;
 padding: 2px;
 border: 2px solid #009;
 }
 .view {
 width: 100px;
 }
 -->
 </style>
 <div class="list">
 <p><span style="color: #900">Transaction #</span>'.$id.'
 <span style="color: #900">Date:</span>'.$date.'
 <span style="color: #900">Time:</span>'.$time.'<span style="color: #900">
 Paid By:</span>'.$paid.' <span style="color: #900">Total:</span>'
 .number_format($total, 2).'
 <form name="form1" method="post" action="find.php">
 <label>
 <input type="submit" name="view" id="view" value="'.$id.'">
 </label>
 </form>
 </p>
 </div>
 <p></p>';
 }
 }
 //view transaction after viewing by month
 if (isset($_POST['view'])){


 $conn = mysql_connect("localhost", "mss_records", "3205") or die(mysql_error());
 mysql_select_db('store_records', $conn) or die(mysql_error());

 $table = $_SESSION['table'];
 echo "this is the number  ".$_POST['view'];
 $post=$_POST['view'];
 echo "this is the post   ".$post;
 $result = mysql_query("SELECT * FROM $table WHERE transaction = '$post'")
 or die(mysql_error());

 while($row = mysql_fetch_array($result))
 {    
 $items=$row['transaction'];
 }
 echo $items;  
 }
 ?>

用户完成第一次选择后,在第二个窗口输出为......

this is the number 46this is the $post 4646 

1 个答案:

答案 0 :(得分:1)

您的查询是mysql_query("SELECT * FROM $table WHERE transaction = '$post'")。因此,$items=$row['transaction'];的值也将为46。当你在没有换行的情况下回应所有内容时,它会将所有内容混合在一起。

POST不会复制任何内容,只是在它之后直接回显$items

试试这个:

$table = $_SESSION['table'];
  echo "this is the number  ".$_POST['view']."<br /> \n";
  $post=$_POST['view'];
  echo "this is the post   ".$post."<br /> \n";
  $result = mysql_query("SELECT * FROM $table WHERE transaction = '$post'")
  or die(mysql_error());

  while($row = mysql_fetch_array($result))
  {    
    $items=$row['transaction'];
  }
  echo $items;  
  }