Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP MySQL
I want to insert multiple products in my database row, For Example:
Purchase Serial:      Products Purchased:
 
      1                Lenovo Z370-59306340
                       Apple MacBook Air MC505 ZP/A 128GB
      
      2                <product>
                       <product>
                       <product>
--------------------------------------------------------------------------
 
Here is my Code for retrieving the values, but when i add it to my database, the first product name will only be added.
foreach($_SESSION['cart'] as $key=>$value)
       {
	$prodid = $value['productid'];
	$qty = $value['qty'];
	$result = mysql_query("SELECT name FROM products WHERE serial = $prodid");
	          while($row = mysql_fetch_array($result)) 
                  {
                   //echo "Name:".$row['name']."<br>Product ID:".$prodid."<br>Quantity:".$qty."<br><br>";
	           $products = $row['name'];
		  }
	$query="UPDATE user_transaction SET product_name = '$products' WHERE serial = 8";
	if (mysql_query($query, $con))
	 {
	   mysql_close($con);
	 }
	else
	die('Error: ' . mysql_error());
 
What could be the best solution for my problem?
 
I'm hoping that you guys will help me, though I'm searching in the internet but I can't find any solution.
 
Thanks and Regards!
Posted 4-Feb-13 19:57pm
Edited 4-Feb-13 20:24pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100