Hi I am creating a shopping basket and I need to retrieve the data that are in the fields but I am struggling to do it and it seems that it doesn't work the way I am doing it. Anyone can help me out ?? Many Thanks.
So this is my basket where it has Name of the product, quantity, price, and total price.
<?php
if(empty($_SESSION['cart'])){
error_reporting(0);
}
$sql= "SELECT * FROM productsoffer WHERE id_product IN(";
foreach($_SESSION['cart']as $id => $value){
$sql.=$id.",";
}
$sql=substr($sql, 0, -1).")ORDER BY name ASC";
$query = mysql_query($sql);
$totalprice=0;
while($row=mysql_fetch_array($query)){
$subtotal=$_SESSION['cart'][$row['id_product']]
['quantity']*$row['price'];
$totalprice+=$subtotal;
?>
<tr>
<td name="name"><?php echo $row['name']?></td>
<td><input type ='text'name='quantity[<?php echo $row['id_product'] ?>]'
size='5' value='<?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?>'/></td>
<td><?php echo $row['price']?>$</td>
<td><?php echo $_SESSION['cart'][$row['id_product']]['quantity']*$row['price'] ?>$</td>
</tr>
<?php}?>
<tr>
<td>Total Price: <?php echo $totalprice+$totalprice1?></td>
</tr>
</table>
<br />
<button type="submit" name="submit">Update Cart </button>
</form>
<form action="indexx.php?page=cart" method="post"/>
<button type="submit" name="submitt">Submit Order </button>
</form>
<br />
<p>To remove an item set its quantity to 0</p>
</tr>
What I need is to store the values of my basket like name,price,quantity in another table in my database for instance table called order.
Here is my attempt but it seems that is not working.
<?php
if (isset($_POST['submitt'])){
$sql="INSERT INTO orders(name,quantity,totalprice) VALUES
('$_POST[name]','$_POST[quantity]','$_POST[totalprice]')";
mysql_query($sql);
}
?>
Any advice is much appriciated. Thanks.