How to edit product quantity in shopping cart?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xuanlee02
Forum Newbie
Posts: 4
Joined: Fri Nov 27, 2009 9:57 pm

How to edit product quantity in shopping cart?

Post by xuanlee02 »

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...
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: How to edit product quantity in shopping cart?

Post by daedalus__ »

post your "codes" so we may crack them!
xuanlee02
Forum Newbie
Posts: 4
Joined: Fri Nov 27, 2009 9:57 pm

Re: How to edit product quantity in shopping cart?

Post by xuanlee02 »

<?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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: How to edit product quantity in shopping cart?

Post by daedalus__ »

okay. what does $product_quantity equal when you try to update?

whats the sql query look like?

oh and use code tags
xuanlee02
Forum Newbie
Posts: 4
Joined: Fri Nov 27, 2009 9:57 pm

Re: How to edit product quantity in shopping cart?

Post by xuanlee02 »

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>
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: How to edit product quantity in shopping cart?

Post by daedalus__ »

:|

the input is named "quantity"

but you ask for the value of $_POST['product_quantity'];
xuanlee02
Forum Newbie
Posts: 4
Joined: Fri Nov 27, 2009 9:57 pm

Re: How to edit product quantity in shopping cart?

Post by xuanlee02 »

Thanks for showing me the errors that i made. :oops:

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 ? :(
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: How to edit product quantity in shopping cart?

Post by daedalus__ »

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!
Post Reply