Reputation: 465
<?php
session_start();
$_SESSION[] = array('itemName'=> "'".$_POST["name"]."'",
'itemPrice'=> "'".$_POST["price"]."'"
);
print_r($_SESSION);
?>
I am posting the data through jQuery, and although the print_r
displays correct data, but PHP above doesn't save in session, any idea?
Upvotes: 1
Views: 4433
Reputation: 7830
You have to use $_SESSION['name']
to store to session, not just $_SESSION[]
<?php
session_start();
$_SESSION['name'] = array('itemName'=> "'".$_POST["name"]."'",
'itemPrice'=> "'".$_POST["price"]."'"
);
print_r($_SESSION);
?>
Upvotes: 2
Reputation: 5520
You will have to give some kind of index/key (name) to the session-variable, so PHP know how to refer to it.
Here's how $_SESSION['test'] is assigned:
$_SESSION['test'] = array('itemName'=> "'".$_POST["name"]."'",
'itemPrice'=> "'".$_POST["price"]."'"
);
Upvotes: 2