PHP Arrays and in_array() function

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
awarraicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nplibCommented:
That's easy

$_SESSION['mark_array'] is not an array

$_SESSION is the array

if (in_array($mark_id, $_SESSION)) echo "not in array";
0
awarraicAuthor Commented:
somehow the array is not working, nothing shows up on page 2, I printed the output on page 1, works fine but... anyway, I am gona try something else. I am just going to pass a value through session variable.
How do I add a session variable instead of the variable $id bellow in the code.
Thanks much.

Print "<td><a href=/content/mark.php?vendor_id=$vendor_id&amp;mark_id=$id>"; echo $mark_name; "</a></td>";
0
nplibCommented:
on page 2 do you have reference to the session variable.

<?php
session_start();
$variable = $_SESSION['mark_array'];
?>
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

awarraicAuthor Commented:
Yea I do.
I am just trying to figure out how to combine html code with php code and pass a session variable along with query string. for example in the code bellow
Print "<td><a href=/content/mark.php?vendor_id=$vendor_id&amp;mark_id=$id>"; echo $mark_name; "</a></td>";

I want to pass $_session['variable_name'] instead of "$id" in the code above.
0
nplibCommented:
post the code of page 2.
0
awarraicAuthor Commented:
Here's the page 2 code:
<?
session_start();
$mark_id = trim($_GET['mark_id']);
$vendor_id = trim($_GET['vendor_id']);

echo $mark_id;
echo $_SESSION[0];
echo $_SESSION[1];
echo $_SESSION[2];
echo $_SESSION[3];
echo $_SESSION[4];
//echo $vendor_id;
//echo  $_SESSION['logged_in'];
//echo $_SESSION['mark_array'][2];
//if (!in_array(trim($mark_id), $_SESSION)) header("Location:login.php");
// or (!$vendor_id) or (!$mark_id)

But, can I just get the help in just the question bellow.
I want to pass $_session['variable_name'] instead of "$id" in the code bellow.
Print "<td><a href=/content/mark.php?vendor_id=$vendor_id&amp;mark_id=$id>"; echo $mark_name; "</a></td>";
0
nplibCommented:
you can't get variable name, just the variable value from the $_SESSION variable.
0
awarraicAuthor Commented:
Dude, are you even reading my coments/question?
This is what I am looking for if you can help me please, if not thanks for your time.
Can I just get the help in just the question bellow.
I want to pass $_session['variable_name'] instead of "$id" in the code bellow.
Print "<td><a href=/content/mark.php?vendor_id=$vendor_id&amp;mark_id=$id>"; echo $mark_name; "</a></td>";
0
nplibCommented:
Sorry, it's they way you asked the question.

Print "<td><a href=/content/mark.php?vendor_id=$vendor_id&amp;mark_id=".$_SESSION['vairable_name'].">"; echo $mark_name; "</a></td>";
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nplibCommented:
you need to define $_SESSION['variable_name'] somewhere though, perhaps on page1
0
darron_chapmanCommented:
Print "<td><a href=/content/mark.php?vendor_id=$vendor_id&amp;mark_id=".$_session['variable_name'].">"; echo $mark_name; "</a></td>";

But the whole point of session variables is so that you don't have to pass them from page to page using query strings or form posts... on the second page you could do this:

session_start();
$id=$_session['variable_name'];

and you wouldn't have to pass it on through the URL
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.