2012-03-13 55 views
1

我甚至不知道怎么谷歌这一个...想象它是什么傻事......但任何帮助将是巨大的......

提交表单时传递变量。 ..when呼应$ _ 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 
+0

考虑作出的[SSCCE(http://sscce.org/),所以我们可以更清楚地发现你的错误 – Jon 2012-03-13 00:53:23

+0

Ι不认为这是与复制相关如你所说$ post变量。我认为最后一个echo $ items;声明打印46这样你可以获得4646当脚本终止。尝试注释脚本中的最后一个回显。 – Andreas 2012-03-13 00:54:37

回答

1

您的问与答uery是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; 
    } 
+1

OMG ......我要睡觉......你是非常正确的。我有错误的MYSQL排在我的代码......在以前的选择46会一直选择查看[“交易”]和在这个选择中,$ post应该是['items'],因为$ post ...所以我只是打电话给它两次.... WOW ...谢谢你们!回声是我只是想弄清楚发生了什么......所以这让事情变得更糟,没有换行符......大声笑 – dave 2012-03-13 03:10:29