2012-03-13 51 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