I'm trying to insert data to database.
There is no error, but the database is still not being updated.
In the database, the product table contains:
productid, categoryid, productname, productimage, stock, price
and the detailsales table contains:
transactionid, productid, and quantity
The update one is working, but the insert one is not working at all.
Here is my code:
<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>
Here is the doShop code:
<?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");
?>
Can anyone help me?
mysql_error().mysql_queryhas been deprecated.