kamran193 Posted January 10, 2012 Share Posted January 10, 2012 can someone help to add new products and increase the quantity of the product when pressing the + button, but it works for [-] <?php include "./php/connection.php"; function products () { $query = "SELECT * FROM product"; if (@mysql_num_rows($query)==0) { echo "There are no products to display!"; } else { while ($query_row = mysql_fetch_array($query)) { print "<div class='product'>" . "<img class='img' src=". $row["Image"]." alt='phone' width='100' height='150' />" . "<p class='name'>".$row["Name"]."</p>". "<p class='price'>£". $row["Price"] ."</p>". "<p><a href='./cart.php?ProductID=". $row["ProductID"]."' class='myButton'>More Info</a></p>". "</div>"; } } } if (isset($_GET['ProductID'])) { $quantity = mysql_query('SELECT * FROM product WHERE ProductID = ' .$_GET["ProductID"]); while ($quantity_row = mysql_fetch_array($quantity)) { if ($quantity_row["Quantity"]!=@$_SESSION["cart_".$_GET["ProductID"]]) { @$_SESSION["cart_".$_GET["ProductID"]]+="1"; } } } if (isset($_GET["remove"])) { $_SESSION["cart_".$_GET["remove"]]--; header("Location: ./cart.php"); # Go back to the login pages } if (isset($_GET["delete"])) { $_SESSION["cart_".$_GET["delete"]]="0"; header("Location: ./cart.php"); # Go back to the login pages } function paypal_items() { $num = 0; foreach($_SESSION as $name => $value) { if ($value!=0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query('SELECT ProductID, Manufacturer, model, Price FROM product WHERE ProductID =' .$productid); while ($query_row = @mysql_fetch_array($query)) { $num++; echo '<input type="hidden" name="item_number_'.$num.'" value="'.$productid.'">'; echo '<input type="hidden" name="item_name_'.$num.'" value="'.$query_row['Name'].'">'; echo '<input type="hidden" name="amount_'.$num.'" value="'.$query_row['Price'].'">'; echo '<input type="hidden" name="shpping_'.$num.'" value="0">'; echo '<input type="hidden" name="shpping_'.$num.'" value="0">'; echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">'; } } } } } function cart () { print "<table id='producttable' border='1'>". "<tr>". "<td class='td top'>Delete</td>". "<td class='td top'>Product Name</td>". "<td class='td top'>Quantity</td>". "<td class='td top'>Price</td>". "<td class='td top'>Sub Total</td>". "</tr>"; foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query('SELECT * FROM product WHERE ProductID =' .$productid); while ($query_row = @mysql_fetch_array($query)) { $sub = $query_row["Price"] * $value; print "<tr>". "<td class='td'><a href='./cart.php?delete=".$productid."'> [Delete] </a></td>". "<td class='td'>".$query_row["Manufacturer"]."</td>". "<td class='td'>".$value."</td>". "<td class='td'><a href='./cart.php?ProductID=".$productid."'> [+] </a>£".$query_row["Price"]."<a href='./cart.php?remove=".$productid."'> [-] </a></td>". "<td class='td'>£".$sub."</td>". "</tr>"; } } @$total += $sub; } } if (@$total==0) { echo "<p>Your basket is empty</p>"; } else { echo @" Total: £" .$total; ?> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="kamran193@hotmail.co.uk"> <?php paypal_items(); ?> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<?php echo $total; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> <?php } echo "</table>"; } echo cart(); echo products(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/254731-repeating-products/ Share on other sites More sharing options...
Adam Posted January 10, 2012 Share Posted January 10, 2012 Can you give us more information and post just the relevant code please? Or if it's all relevant try and give a quick breakdown of what's happening. Quote Link to comment https://forums.phpfreaks.com/topic/254731-repeating-products/#findComment-1306173 Share on other sites More sharing options...
kamran193 Posted January 10, 2012 Author Share Posted January 10, 2012 the whole code is relevent , and when you add new product on to the cart it does not update the cart thats in and it will not increse the quantity of the product in the cart if (isset($_GET['ProductID'])) { $quantity = mysql_query('SELECT * FROM product WHERE ProductID = ' .$_GET["ProductID"]); while ($quantity_row = mysql_fetch_array($quantity)) { if ($quantity_row["Quantity"]!=@$_SESSION["cart_".$_GET["ProductID"]]) { @$_SESSION["cart_".$_GET["ProductID"]]+="1"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/254731-repeating-products/#findComment-1306207 Share on other sites More sharing options...
Adam Posted January 10, 2012 Share Posted January 10, 2012 I'm sorry but did you write this? All the threads you've started here have just been a long snippet of code with very little information and you've just asked us to fix it for you. If you did write it, please explain exactly what's going on; what are you requesting to update the quantity, what is happening, what errors are you getting, etc. If you can't answer these questions then you need to post this in the freelance section, because we're not here to do it all for you. Apologies if I've got you wrong, happy to help if you'll provide a better description of the problem. Quote Link to comment https://forums.phpfreaks.com/topic/254731-repeating-products/#findComment-1306214 Share on other sites More sharing options...
kamran193 Posted January 10, 2012 Author Share Posted January 10, 2012 thank you for your reply and i have wrote the code my self, their are no errors that are showing, it is simply not updating the quantity, it will minus it but not update it thank you Quote Link to comment https://forums.phpfreaks.com/topic/254731-repeating-products/#findComment-1306215 Share on other sites More sharing options...
kamran193 Posted January 10, 2012 Author Share Posted January 10, 2012 thank you for the replys i have got it working Quote Link to comment https://forums.phpfreaks.com/topic/254731-repeating-products/#findComment-1306218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.