Jump to content

Inserting Array into MYSQL db


pete212

Recommended Posts

Hi,

 

Please can someone help me. This is driving me up the wall!

 


echo $_SESSION['Cart'][0][$y];

$sql="INSERT INTO BASKET (ORDERID, PRODUCTID, PRODUCTNAME, PRICE)
VALUES ('$orderid','$_SESSION[Cart][0][$y]','$_SESSION[Cart][1][$y]','$_SESSION[Cart][2][$y]')";
    
    if (!mysql_query($sql,$con))
       {
       die('Error: ' . mysql_error());
       }

 

All its simply trying to do is read three array positions into a MSQL table. $orderis is inputted sucessfully, but the array data isnt. For PRODUCTID and PRICE i get 0 in the database and for PRODUCTNAME i'm getting Array[1][0]. I know the array is holding the data properly because the echo before the insert echos out the right data!

 

Any help you can give will be much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/155630-inserting-array-into-mysql-db/
Share on other sites

$sql = sprintf("INSERT INTO BASKET (ORDERID, PRODUCTID, PRODUCTNAME, PRICE) VALUES ('%s', '%s', '%s', '%s')", $orderid,
                                                                                                              $_SESSION['Cart'][0][$y],
                                                                                                              $_SESSION['Cart'][1][$y],
                                                                                                              $_SESSION['Cart'][2][$y]);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.