3 Replies - 931 Views - Last Post: 24 February 2014 - 12:43 AM Rate Topic: -----

#1 mfredy92   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 144
  • Joined: 09-May 13

Add more items to the cart

Posted 22 February 2014 - 09:05 AM

Hello

I am able to add one item to the cat but I want to have more. Can you help me with it. I am using Post method to add items to the cart

while ($row = $stmt->fetch(PDO::FETCH_OBJ)){
	   
	   
	    echo "<table border='3' cellpadding='10' position='relative` bottom= '450px' color = 'blue';>";//start table
        
		echo '<div class="DVD ID">'; 
		echo '<tr><td>DVD Id : '.$row->DVDID. '<br></td>' ;
		echo '<td>Name Of the DVD : '.$row->NameOfTheDVD.'<br></td>';
        echo '<td>Quantity :  '.$row->Quantity.'</td>';
		echo '<td>Price:  '.$row->Price.'</td></tr> ';
		
		$mydvd = $row->DVDID;
		$name = $row->NameOfTheDVD;
		$Quantity = $row -> Quantity;
		$Price = $row -> Price;
		
		echo $mydvd;
		//echo '<form method="post" action="basket.php?id='.$mydvd.'">';
        
		echo '<input type="hidden" name="id" value="'.$mydvd.'">';
		echo '<input type="hidden" name="item" value="'.$name.'">';
		echo '<input type="hidden" name="Quantity" value="'.$Quantity.'">';
		echo '<input type="hidden" name="Price" value="'.$Price.'">';
		echo '<input type="hidden" name="Cart" value="'.$cartItemCount.'">';
		//echo '<input type="submit" value="Add To Basket">';
		echo '<a href = "basket.php?id='.$mydvd.'&name='.$name.'&Quantity='.$Quantity.'&Cart='.$cartItemCount.'&Price='.$Price.'"> Add To Basket</a><br>';
        
        
		
		}


ABove code adds to the cart

$myid = $_GET['id'];
	$DVDname = $_GET['name'];
	$Qty = $_GET['Quantity'];
	$price = $_GET['Price'];
	
	
	echo '<div class="DVD ID">';
	echo '<h1> Cart </h1>';
    echo '<table border="1" cellspacing="1" position="relative" left="250">';
    echo  "<tr><th> DVD ID<td> " . $myid .  "</td></th></tr>";
	echo  "<tr><th> DVD Name<td> " . $DVDname .  "</td></th></tr>";
	echo  "<tr><th> Quantity<td> " . $Qty .  "</td></th></tr>";
	echo  "<tr><th> Price<td> " . $price .  "</td></th></tr>";



This code prints it out in a table format

Thank u for ur help.

Is This A Good Question/Topic? 0
  • +

Replies To: Add more items to the cart

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,563
  • Joined: 08-June 10

Re: Add more items to the cart

Posted 23 February 2014 - 12:59 AM

Quote

I am able to add one item to the cat but I want to have more.

use a form to add more than one item at once to the cat.
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb   User is online

  • D.I.C Lover
  • member icon

Reputation: 3837
  • View blog
  • Posts: 13,994
  • Joined: 08-August 08

Re: Add more items to the cart

Posted 23 February 2014 - 07:55 AM

Why do you have hidden values? They're not hidden from a hacker. I'd use and array of objects to store the cart, and I'd put that in a session variable.

I'd use Ajax to add items to the cart.

This post has been edited by CTphpnwb: 23 February 2014 - 07:56 AM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,563
  • Joined: 08-June 10

Re: Add more items to the cart

Posted 24 February 2014 - 12:43 AM

Quote

I am sorry for messaging you but u replied to my thread. And I did not understand what you meant by ur comment. Can you explain?

judging from the given coding, your "add to cart" is a link that directly takes you to the script given in the href attribute (with the passed values). so if you click on that link, only the data given in this link will be transferred to the PHP script.

on the other hand side, a form will submit any data its named form elements (text boxes, checkboxes, etc.) contain and you’re able to modify a form’s content with Java­Script to build the data you want.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1