We help IT Professionals succeed at work.

How to create/save a session array and then test a record if it exist in that session array

awarraic asked
I am trying to save some records in a session array, how do I create a session array? and how to I save the data into the array and then compare the data in that array.
Watch Question

Start a session with session_start();
The $_SESSION[] array is a superglobal so it is always created for you. All you need to do is add keys like this: $_SESSION['something'] = "something";

On every page that you are going to use anything from the $_SESSION array you first need to do a session_start();

$_SESSION['myownsessionname'] = "What ever value I want to give it";

comparing the values in the sessions is up to you,
you have to know what you are comparing for, are you looking for matching string, numbers, how many sessions there are a lot of variables.


I am getting this error when I compare the data:
Warning: in_array() [function.in-array]: Wrong datatype for second argument in D:\Web\vhosts\dev\mark.php on line 11

Here's how I am saving the data into the array on page one:
while($row = mysql_fetch_array($rs))
$_SESSION['mark_array'] = $row["mark_id"];

Here's how I am comparing the data on page two:
if (in_array($mark_id, $_SESSION['mark_array'])) echo "not in array";

Any clues? why it's giving that error above


Still stuck, help please

Explore More ContentExplore courses, solutions, and other research materials related to this topic.