我试图插入数据到数据库。 没有错误,但数据库仍未更新。 在数据库中,product
表包含: 产品ID,类别ID,产品名称,productimage,股票价格 和detailsales
表包含: 的transactionId,产品ID和数量无法插入到mysql数据库
更新一个工作,但插入的一个根本不工作。
这里是我的代码:
<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");
?>
谁能帮助我?
你怎么知道没有错误?你不检查'mysql_error()'。 – andrewsi
['mysql_query'](http://php.net/manual/en/function.mysql-query.php)已被弃用。 – Blazemonger
我总是看到这种类型的问题,你应该阅读[PHP和MySQL的常见数据库调试](http://jason.pureconcepts.net/2013/04/common-debugging-php-mysql/)。 –