提交按钮将HTML表行插入DB表行



有人知道我应该如何设计查询以插入HTML表的一行,该表的内容是从我的DB中的表格中的另一个表中的一个表中的另一个表中的另一个表?我正在为将提交按钮与单个结果行关联而苦苦挣扎。

html-

 <form id="order" name="form1" method="post" action="script/addOrder.php">
    <h3><a id="curry">Curry Dishes:</a></h3><img src="img/curry.jpg" >
        <table class="menu">
            <thead>
                <tr>
                    <th>Dish Name</th>
                    <th>Description</th>
                    <th>Allergy Information</th>
                    <th>Price</th>
                </tr>
            </thead>
        <tbody>
    <?php
            include "script/dbconn.php";
                $sql="SELECT `dish`.`dishName`, `category`.`categoryName`, `allergy`.`allergyName`, `dish`.`dishPrice`, `dish`.`dishDescription` FROM `dish` 
                INNER JOIN category ON dish.categoryID = category.categoryID
                INNER JOIN allergy ON dish.allergyID = allergy.allergyID
                WHERE `categoryName` LIKE 'Curry'
                ORDER BY dishName ASC";
                //-run  the query against the mysql query function
                $result=mysqli_query($conn, $sql);
                //-create  while loop and loop through result set
                while($row=mysqli_fetch_array($result)){
                    $Name=$row['dishName'];
                    $Desc=$row['dishDescription'];
                    $Price=$row['dishPrice'];
                    $Allergy=$row['allergyName'];
                    //-display the result of the array?>
                    <tr>
                        <td><?php echo $Name;?></td>
                        <td><?php echo $Desc;?></td>
                        <td><?php echo $Allergy;?></td>
                        <td><?php echo $Price;?></td>
                        <td><input type="submit" id="submit" name="submit" value="Order"</td>
                    </tr>
            <?php }
    ?>

您可以使用 <button>提交具有指示特定行的值。

<button type="submit" name="dish" value="<?= $row['dishID'] ?>">Order</button>

我使用了" Clisid",尽管我在您的查询中没有看到它。根据其他表,我认为它在那里,因此您只需要将其添加到SELECT中的列列表中。

您将能够从script/addOrder.php中的$_POST['dish']获取单击按钮的值。至于实际插入查询,您需要更具体地说明自己想要做什么。

最新更新