Jump to content

Recommended Posts

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: &pound" .$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();
		?>
            

Link to comment
https://forums.phpfreaks.com/topic/254731-repeating-products/
Share on other sites

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";
					}

				}					
			}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/254731-repeating-products/#findComment-1306207
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/254731-repeating-products/#findComment-1306214
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.