We help IT Professionals succeed at work.
Get Started

PHP $_SESSION passing variable to another page-help with syntax

wilko1000
wilko1000 asked
on
75 Views
Last Modified: 2015-09-25
Hi

I would like to store a userID into $_SESSION then reference the $_SESSION in another page. I get how the Session function supposed to work but need help with the syntax please?

I have  a table called users which stores uid, username and password

I have then started the session function like this

<?php

class DB_Functions {
session_start();

Then tried to use the $_SESSION here:

 /**
     * Get user by email and password
     */
    public function getUserByEmailAndPassword($email, $password) {
        $result = mysql_query("SELECT * FROM users WHERE email = '$email'") or die(mysql_error());
        // check for result
        $no_of_rows = mysql_num_rows($result);
        if ($no_of_rows > 0) {
            $_SESSION[email] =$email
            $result = mysql_fetch_array($result);
            $salt = $result['salt'];
            $encrypted_password = $result['encrypted_password'];
            $hash = $this->checkhashSSHA($salt, $password);
            // check for password equality
            if ($encrypted_password == $hash) {
                // user authentication details are correct
                return $result;
            }
        } else {
            // user not found
            return false;

Then called it in the next page as below:
<?php

session_start();

$result = mysql_query("SELECT users.uid, users.name
FROM users
WHERE EXISTS (SELECT 0 FROM available A1, available A2
WHERE  users.uid <> $_SESSION[email])") or die(mysql_error());

But got syntax error

How do i store the ID from the user returned in the 1st query then pass to the second query correctly?
Comment
Watch Question
Fixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE