[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

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

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.
thanks
0
awarraic
Asked:
awarraic
  • 2
1 Solution
 
steezyCommented:
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();
0
 
nplibCommented:
<?php
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.
0
 
awarraicAuthor Commented:
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
0
 
awarraicAuthor Commented:
Still stuck, help please
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now