Display data from database by spcific id
<p>I create the simple cart app. In these i want to add the product to the cart, from that cart i choose only one product to be buy. I getting confuse in using id. can anyone help me to solve this problem?</p>

<p>here is the code for adding to the cart:</p>

<pre><code>&lt;?php     
Include('connect.php');

$productId=$_POST['productId'];
$productName=$_POST['productName'];
$productPrice=$_POST['productPrice'];
$quantity=$_POST['quantity'];

$sql=mysql_query("INSERT INTO products    (productId,productName,productPrice,quantity) 
VALUES ('$productId','$productName','$productPrice','$quantity')") or     die(mysql_error());

if($sql){ 

$_GET['productId']=$productId;
header('Location:buy.php');
} 
else
{
echo"Failed to add cart !";

}
?&gt;
</code></pre>

<p>Here is the code for fetching product and display:</p>

<pre><code> &lt;?php 
 include('connect.php');




 $sql="SELECT productName FROM products WHERE productId=" . $productId . "";

 $result = mysql_query($sql);

 $myArray = array(); 

 echo "&lt;table  style='width:50%;'&gt;
 &lt;tr&gt;
&lt;th&gt;Product Name&lt;/th&gt;
&lt;th&gt;Product Price&lt;/th&gt;
&lt;th&gt;Quantity&lt;/th&gt;

&lt;/tr&gt;";

 $index = 0;
while($row = mysql_fetch_assoc($result))
{ 
 $myArray[$index] = $row;
 $index++;

 echo "&lt;tr&gt;";
 echo "&lt;td&gt;" . $row['productName'] . "&lt;/td&gt;";
 echo "&lt;td&gt;" . $row['productPrice'] . "&lt;/td&gt;";
 echo "&lt;td&gt;" . $row['quantity'] . "&lt;/td&gt;";
 echo "&lt;/tr&gt;";
 }

?&gt;
</code></pre>