I have a problem in my codes when i tried to edit quantity in my shopping cart.
For example, i wanted to change 2 to 3 quantity for a product. But it ends up to 0. I dunno what problem in my codes
Can anyone help me? Thank you...
How to edit product quantity in shopping cart?
Moderator: General Moderators
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: How to edit product quantity in shopping cart?
post your "codes" so we may crack them!
Re: How to edit product quantity in shopping cart?
<?php
session_start();
require_once 'opendb.php';
include 'banner.php';
$id=$_SESSION['id'];
$product_quantity=trim($_POST['product_quantity']);
$sql = "UPDATE cart SET product_quantity='$product_quantity' WHERE member_id=$id";
$result = mysql_query($sql) or die(mysql_error());
echo "You have successfully updated your cart.<br>";
echo "<meta http-equiv='refresh' content='2; url=view_cart.php'>";
?>
The total price will be calculated in view_cart.php
But i do not understand why everything still end up to be 0.
session_start();
require_once 'opendb.php';
include 'banner.php';
$id=$_SESSION['id'];
$product_quantity=trim($_POST['product_quantity']);
$sql = "UPDATE cart SET product_quantity='$product_quantity' WHERE member_id=$id";
$result = mysql_query($sql) or die(mysql_error());
echo "You have successfully updated your cart.<br>";
echo "<meta http-equiv='refresh' content='2; url=view_cart.php'>";
?>
The total price will be calculated in view_cart.php
But i do not understand why everything still end up to be 0.
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: How to edit product quantity in shopping cart?
okay. what does $product_quantity equal when you try to update?
whats the sql query look like?
oh and use code tags
whats the sql query look like?
oh and use code tags
Re: How to edit product quantity in shopping cart?
These are the codes in my edit_quantity.php, just now the codes are in do_edit_quantity.php
edit_quantity.php
<form enctype='multipart/form-data' action='do_edit_quantity.php' method='POST'>
<?php
$sql="SELECT member_name, cart.member_id, product_quantity, cart.product_id, product_name, product_category, product_category.product_category_id
FROM member, cart, product, product_category
WHERE member.member_id = cart.member_id
AND cart.product_id = product.product_id
AND product.product_category_id = product_category.product_category_id
AND cart.member_id='$id'";
$result= mysql_query($sql) or die (mysql_error());
while ($row=mysql_fetch_array($result))
{
$member_name=$row['member_name'];
$product_name=$row['product_name'];
$product_category=$row['product_category'];
echo "<font size='4' color='#CC3333'><b>Edit Quantity</b></font><br><br>
<table border='0'>
<tr><td>".$row["member_name"]."</td></tr>
<td>".$row["product_category"]."</td></tr>
<td>".$row["product_name"]."</td></tr>
<td id='word'>Product Quantity</td><td>:</td><td><input type='text' name='quantity' id='quantity' value='".$row["product_quantity"]."'></td>
</tr><tr height='5px'></td><tr>
<td></td><td></td><td><input name='submit' value='UPDATE' type='submit'></td></tr>
</table>
";
}
?>
</form>
edit_quantity.php
<form enctype='multipart/form-data' action='do_edit_quantity.php' method='POST'>
<?php
$sql="SELECT member_name, cart.member_id, product_quantity, cart.product_id, product_name, product_category, product_category.product_category_id
FROM member, cart, product, product_category
WHERE member.member_id = cart.member_id
AND cart.product_id = product.product_id
AND product.product_category_id = product_category.product_category_id
AND cart.member_id='$id'";
$result= mysql_query($sql) or die (mysql_error());
while ($row=mysql_fetch_array($result))
{
$member_name=$row['member_name'];
$product_name=$row['product_name'];
$product_category=$row['product_category'];
echo "<font size='4' color='#CC3333'><b>Edit Quantity</b></font><br><br>
<table border='0'>
<tr><td>".$row["member_name"]."</td></tr>
<td>".$row["product_category"]."</td></tr>
<td>".$row["product_name"]."</td></tr>
<td id='word'>Product Quantity</td><td>:</td><td><input type='text' name='quantity' id='quantity' value='".$row["product_quantity"]."'></td>
</tr><tr height='5px'></td><tr>
<td></td><td></td><td><input name='submit' value='UPDATE' type='submit'></td></tr>
</table>
";
}
?>
</form>
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: How to edit product quantity in shopping cart?
the input is named "quantity"
but you ask for the value of $_POST['product_quantity'];
Re: How to edit product quantity in shopping cart?
Thanks for showing me the errors that i made.
I can edit the quantity in my cart already.
However, when i added 2 or above products in my cart, i am unable to edit quantity for product individually.
For example, I have 2 products in my cart now. When i edit quantity for 1st product, the 2nd product's quantity will follow the 1st product's quantity.
Does codes has some more errors ?
I can edit the quantity in my cart already.
However, when i added 2 or above products in my cart, i am unable to edit quantity for product individually.
For example, I have 2 products in my cart now. When i edit quantity for 1st product, the 2nd product's quantity will follow the 1st product's quantity.
Does codes has some more errors ?
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: How to edit product quantity in shopping cart?
im not sure i understand the problem but ill bet it has to do with your sql query. ill pick up on this tomorrow. keep experimenting! pretend you are a php scientist!