我正在尝试将数据插入数据库。没有错误,但数据库仍未更新。在数据库中,product
表包含:productid、categoryid、productname、productimage、stock、price,detailsales
表包含:transactionid、productid、数量
更新一个正在工作,但插入一个根本不起作用。
这是我的代码:
<form action="doShop.php" method="post">
<table border="1">
<tr>
<td>Product ID</td>
<td>Product Name</td>
<td>Product Image</td>
<td>Price</td>
<td>Product Stock</td>
<td> Quantity</td>
</tr>
<?php
$query = mysql_query("SELECT * FROM Product");
while($row = mysql_fetch_array($query)){
?>
<tr>
<td><input type="text" value="<?=$row['ProductID']?>" name="productid"></td>
<td><?=$row['ProductName']?></td>
<td><img src="image/<?=$row['ProductImage']?>"></td>
<td><?=$row['Price']?></td>
<td><input type="text" value="<?=$row['Stock']?>" name="stock"></td>
<td><input type="text" name="quantity"></td>
</tr>
<?php
}
print mysql_error();
?>
</table>
<table>
<tr><input type="submit" value="Submit"></tr>
</table>
</form>
这是doShop代码:
<?php
include("connect.php");
$id=$_REQUEST['productid'];
$quantity=$_REQUEST['quantity'];
$stock = $_REQUEST['stock'];
mysql_query("insert into DetailSales(ProductID, Quantity)values('".$id."','".$quantity."')");
mysql_query("update product set stock = $stock - $quantity where detailsales.productid = product.productid");
header("location:shopcart.php");
?>
谁能帮我?