Jump to content

[SOLVED] SESSION VALUES INTO MYSQL


serbestgezer

Recommended Posts

Hi There,

I am trying to get session cart values into order_items table

<?php 
$cart = $_SESSION[cart];
$a = array($cart);
//echo $cart;

foreach($a as $data)
{
echo $data; // 1,1,1,1
//$sql = mysql_query("insert into order_items (code) VALUES ('$data')")  or die(mysql_error());
}
?>

 

I dont know what i am doing wrong. it enters the data like 1,1,1,1 doesnt repeats the insert

 

I want it like that

 

order_items table

id      code

1        1

2        1

3        1

4        1

 

 

How can I get the session values and insert them into database?

Link to comment
https://forums.phpfreaks.com/topic/176130-solved-session-values-into-mysql/
Share on other sites

I changed the code as below.

 

$cart = $_SESSION['cart'];
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item => $value) {
print_r($contents[$value]);
	}

 

doesnt print anything but if I use print_r($contents[$value] . "test ");  it prints //test test test test  I dont get the session value ????

according to your code if it goes like this.

 

then the $cart << was a string no matter where it come from....

 

<?php session_start();
$_SESSION['cart']="1,1,1,1"; 
$cart = explode(',', $_SESSION['cart']);
foreach($cart as $data) {
echo $data;
}
?>

 

result.

1111

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.