Page 1 of 1

Problem while post data to other page

Posted: Wed Sep 07, 2005 9:04 am
by eshban
HI,

I have a php page in which i have different products. I retrieve these products from database. Mean a loop runs and one by one it will retrieve all the products from the database.

Then i add a simple button "ADD to cart".

this button will repeat will displayed at every product.

Means if there are 6 products, then it will show 6 buttons of "Add to CART".

I want that if user click on first "add to cart" button, then it will post the values of only first product to database. If if user click on second "add to cart" button, then it will post the values of only second product to database.


But add to cart button just send the values of only first prodcut.

Kindly help me in this regard.


Here is my sample code.

Code: Select all

$query = mysql_query("Select * from newproductinfo where pid=$pageid",$db) or die ("Error");
	$rowcount=0;  //count the iterations of loop to control the table structure
	
	while ($result = mysql_fetch_array($query))	
	{
		$pid=$result['pid'];		
		$ppid=$result['productid'];
		print "<br> $ppid";
		
		$title=$result['title'];
		$pname=$result['productname'];
		$desc=$result['description'];
		$size=$result['size'];
		$image=$result['image'];		
		$price = $result['price'];
		$a = $result['image'];

			if($rowcount==2){
	
				echo"</tr>";
				echo"<tr>";
				echo"<td width='50%' height='399' align='left' valign='top'>";
				$rowcount=1;	
			}
	
			else{
	
				echo "<td width='50%' height='399' align='left' valign='top'>";	
				$rowcount = $rowcount+1;
			}

     	////////////// Displaying Image and other things///////////////////////////////////////
							
	echo"<center><img src='images/".$a."'height='180' width='200'></center>";
	echo "<br><br>$ppid<br>  $title<br>  $pname<br>  $desc<br>  $size<br>  $price<br><br>";
	
	echo"<form action='test.php?btn=$ppid' method='post'>";
	echo"<center><input type='submit' name='SUBMIT[]' value='Add to Cart'></center>";
	
	
	echo"</td>";		
	
	}  //while Loop Ends
	echo"</form>";
kindly correct this code, so that it will only send the information of that product, which i clicked.

with this code it will only sent the first value of $ppid to other page.

bye

Burrito: PHP tags you should use when posting code in the forums you are.

Posted: Wed Sep 07, 2005 10:40 am
by John Cartwright
have seperate forms for each product.