2012-09-21 35 views
-1

我试图从db中检索记录并将它们放入表格中。我想有一个可以做一些处理的更新按钮。这是代码。它输出正确。但更新按钮(图像)不起作用。请帮助从表格中发布表格

<?php 
echo "</br>"; 
echo "<table border='1'> 
<tr> 
<th>Order ID</th> 
<th>Customer Number</th> 
<th>Order Items</th> 
<th>Transaction Time</th> 
<th>Amount</th> 
</tr>"; 
$con = mysql_connect('localhost', 'root', ''); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 

mysql_select_db("kaka", $con); 

$sql="SELECT * FROM orders WHERE status = 'NRDY'"; 
$result2 = mysql_query($sql); 
while($row1 = mysql_fetch_array($result2)) 
    { 
    echo "<div class=\"update\"><form method='post' action=\"test.php\">\n"; 
    echo "<tr>"; 
    echo "<td><input type='hidden' name='order_id' value='".$row1['order_id']."'>" .$row1['order_id']. "</td>"; 
    echo "<td><input type='hidden' name='cust_num' value='".$row1['cust_num']."'>" .$row1['cust_num']. "</td>"; 
    echo "<td><input type='hidden' name='items' value='".$row1['items']."'>" .$row1['items']. "</td>"; 
    echo "<td><input type='hidden' name='order_time' value='".$row1['order_time']."'>" .$row1['order_time']. "</td>"; 
    echo "<td><input type='hidden' name='order_id' value='".$row1['amount']."'>" .$row1['amount']. "</td>"; 
    //echo "<td>" . $row1['order_id'] . "</td>"; 
    //echo "<td>" . $row1['cust_num'] . "</td>"; 
    //echo "<td>" . $row1['items'] . "</td>"; 
    //echo "<td>" . $row1['order_time'] . "</td>"; 
    //echo "<td>" . $row1['amount'] . "</td>"; 
    echo "<td>" . "<input type=\"image\" src=\"images/update.png\" alt=\"Update Row\" class=\"update\" title=\"Update Row\">\n" . "</td>"; 
    echo "</tr>"; 
    echo "</form></div>"; 
    } 

echo "</table>"; 
?> 

这里是test.php的

<?php 
echo $_POST['order_id']; 
?> 
+0

不要在新代码中使用'mysql_ *'函数。 [手册页](http://php.net/mysql_query)上的大红色框出于某种原因。 – Quentin

回答

1

使用a validator。你不能在表格行周围包装div或表单。有些浏览器通过移动div/form来恢复此错误,因此它位于表格之外(将内容留下)。因此,您的投入不在表单内,因此不应期望执行任何操作。

+0

有什么我想要做的更简单的方法? – user1051505