有谁知道我应该如何设计一个查询来将 HTML 表的一行(其内容来 self 的数据库中的表)插入到我的数据库中的另一个表中?我正在努力将提交按钮与各个结果行相关联。
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>
我使用了“dishID”,尽管我在您的查询中没有看到它。根据其他表,我认为它就在那里,因此您只需将其添加到 SELECT 中的列列表中即可。
您将能够从 $_POST['dish']
获取单击按钮的值在script/addOrder.php
。就实际的插入查询而言,您需要更具体地说明您希望它执行的操作。
关于php - 提交按钮将 HTML 表行插入 DB 表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43789788/