[英]Submit button to insert HTML table row into DB table row
有誰知道我應該如何設計查詢以將HTML表的一行插入到數據庫的另一個表中,該行的內容來自數據庫中的一個表? 我正在努力將“提交”按鈕與各個結果行相關聯。
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的列列表中即可。
您將可以從script/addOrder.php
$_POST['dish']
獲得clicked按鈕的值。 至於實際的插入查詢,您需要對要執行的操作更具體。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.