0

我有多本书可供人们订购。所有这些书都存储在 MySQL 数据库中。人们可以在文本字段中输入值 (INT)。示例:第一册值 = [5]。但是当我输入提交时,它只会显示该文本字段的最后输入值。

我该如何安排,如果人们只在某些文本字段中输入值然后点击提交,他们会看到他们订购的产品及其价值。谢谢 :)

我的代码

            <table width="990">
        <form name="form" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
        <tr>
            <td width="93" class="main">Bestelnummer</td>
            <td width="550" class="main">Titel</td>
            <td width="100" class="main">Categorie</td>
            <td width="150" class="main">Type Onderwijs</td>
            <td width="80" class="main">Groep</td>
            <td width="50" class="main">Prijs</td>
            <td width="40" class="main">Aantal</td>
        </tr>
<?php
    // Laat Resultaten zien
    $s = "SELECT * FROM producten ORDER BY id ASC";
    $sql = (mysql_query($s))or die ("FOUT: " . mysql_error());   
    while($row = mysql_fetch_array($sql))
    { 
        $id = $row['id'];
        echo "<tr>";
        echo "<td width='93'>" .$row['bestelnummer']. "</td>"; 
        echo "<td width='550'><a href='".$row['link']."' target='_blank' title='".$row['titel']."' >" .$row['titel']. "</a></td>"; 
        echo "<td width='100'>" .$row['categorie']. "</td>";
        if ($row['onderwijs'] == "BO") { echo "<td width='150'>Basis Onderwijs</td>"; } elseif ($row['onderwijs'] == "VO") { echo "<td width='150'>Voortgezet Onderwijs</td>"; } else { }
        echo "<td width='80'>" . $row['groep'] . "</td>"; 
        if ($row['prijs'] == 0) { echo "<td width='50'><i>gratis</i></td>"; } else { echo "<td width='50'>&euro; " .$row['prijs']. "</td>"; }
        echo "<td width='40'><input type='text' name='nummer".$id."' title='nummer".$id."' class='aantal' maxlength='4' /></td>";
        echo "</tr>";
    }
?>
        <tr>
            <td><input type="submit" name="submit" value="Plaats bestelling" class="verzend"/></td>
        </tr>
        </form> 
        </table>
        <?php if (isset($_POST['submit']))
        {
            if (empty($_POST['aantal']))
            {
                echo "L33g";    
            }
            else
            {
                $_POST['nummer".$id."'];
            }
        }?>
4

1 回答 1

0

你最好使用数组,所以使用

<input type='text' name='nummer[".$id."]' title='nummer".$id."' class='aantal' maxlength='4' />

然后更换

$_POST['nummer".$id."'];

foreach($_POST['nummer'] as $value) {
    echo $value;
}
于 2012-08-30T13:38:09.993 回答