PHP函数获取发布值

PHP函数获取发布值,php,Php,我有以下PHP/HTML代码: <form method="post" action="create_quote2.php"> <table width="800" border="0" cellspacing="5" cellpadding="5"> <tr> <td><strong>Select</strong></td> <td><strong>Image<

我有以下PHP/HTML代码:

<form method="post" action="create_quote2.php">
<table width="800" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td><strong>Select</strong></td>
    <td><strong>Image</strong></td>
    <td><strong>Name</strong></td>
    <td><strong>Sale Price</strong></td>
    <td><strong>Quantity</strong></td>
  </tr>
<?php
$sql="SELECT * from products ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$counter=0;
while($result=mysql_fetch_array($rs))
{
    $counter++;
    echo '<input type="hidden" name="product'.$counter.'" value="'.$_POST["checkbox$i"].'" />';
    echo '<tr>
                <td><input type="checkbox" value="'.$result["sequence"].'" name="checkbox'.$counter.'" /></td>
                <td>Image</td>
                <td>'.$result["title"].'</td>
                <td>&pound;'.$result["saleprice"].'</td>
                <td><input type="text" name="qty" id="qty" size="20" /></td>
              </tr>';
}
echo '<input type="hidden" name="counter" value="'.$counter.'" />';
?>
</table>
<input type="submit" name="submit" value="Next" />
</form>

选择
图像
名称
销售价格
数量
因此,选中复选框后,您将使用以下代码进入下一页:

<table width="800" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td><strong>Image</strong></td>
    <td><strong>Title</strong></td>
    <td><strong>Sale Price</strong></td>
    <td><strong>Trade Price</strong></td>
    <td><strong>Quantity</strong></td>
    <td><strong>Total Cost</strong></td>
  </tr>
<?php
for($i=1; $i<=$_POST["counter"]; $i++)
{
    if($_POST["checkbox$i"])
    {
        $counter++;
        $sql="SELECT * from products where sequence = '".$i."' ";
        $rs=mysql_query($sql,$conn) or die(mysql_error());
        $result=mysql_fetch_array($rs);     
        echo '<tr>
                    <td>Image</td>
                    <td>'.$result["title"].'</td>
                    <td>&pound;'.$result["saleprice"].'</td>
                    <td>&pound;'.$result["tradeprice"].'</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>';   
    }
}
?>
</table>

图像
标题
销售价格
交易价格
数量
总成本
它工作正常,并从products表中选择所有正确的产品,但我需要一种方法来获取每行的过账数量值

如何在第二页上显示已过帐的数量值


另外,我不担心在这段代码上注入SQL…

要得到您的数量,只需更改:

<input type="text" name="qty" id="qty" size="20" />


然后以与其他输入相同的方式引用。

在第一页使用

然后在相关单元格中
$\u POST[“qty{$counter}”]
$\u POST[“qty.”$i]

作为补充说明,您可能会发现使用HEREDOC结构更容易,这样您就不必继续向echo内容添加引号:

echo <<<BLOCK
<tr>
    <td>Image</td>
    <td>{$result["title"]}</td>
    <td>&pound;{$result["saleprice"]}</td>
    <td>&pound;{$result["tradeprice"]}</td>
    <td>Quantity - {$_POST['qty'.$i]}</td>
    <td>&nbsp;</td>
</tr>

BLOCK;

echo perfect-除了只做一行之外。如果我勾选2个复选框并输入数量,我只会得到第一行的已发布数量等,但结果的标题显示在另一行,我看到我哪里出错了。我想我应该使用
$I
而不是
$counter
。编辑了我的答案。希望这是对的。顺便提一下,
$counter
用于什么?它没有在块中引用$counter从以前就在那里。我现在已经把它取下来了,非常感谢
echo <<<BLOCK
<tr>
    <td>Image</td>
    <td>{$result["title"]}</td>
    <td>&pound;{$result["saleprice"]}</td>
    <td>&pound;{$result["tradeprice"]}</td>
    <td>Quantity - {$_POST['qty'.$i]}</td>
    <td>&nbsp;</td>
</tr>

BLOCK;