1
<?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?

1
  • 1
    put a name inside the brackets of $_SESSION-variable? Commented Apr 24, 2013 at 22:23

2 Answers 2

2

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"]."'"
                        );
Sign up to request clarification or add additional context in comments.

Comments

2

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);
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.