-1

Index.php

    $password = hash('sha256', $pass); // password hashing using SHA256

     $res=mysql_query("SELECT * FROM users WHERE userEmail='$email'");
     $row=mysql_fetch_array($res);
     $count = mysql_num_rows($res); // if uname/pass correct it returns                                must be 1 row

     if( $count == 1 && $row['userPass']==$password ) {
     $_SESSION['user'] = $row['userId'];
     $_SESSION['location'] = $row['userLocation'];
    header("Location: home.php");
   } else {
    $errMSG = "Incorrect Login";
   }

Home.php

 $query = "SELECT * FROM machines WHERE locatie=".$_SESSION['location']; 
 $result = mysql_query($query);

Why Does this not work?? I can't figure out why the $_SESSION['locatie'] part does not work?? I thought it has the same value as in the other file.

Jaap
  • 81,064
  • 34
  • 182
  • 193
Jelle N
  • 1
  • 3

3 Answers3

1

There is a syntax error in your mysql query.

 $query = "SELECT * FROM machines WHERE locatie='".$_SESSION['location']."'"; 
Khan Afzal
  • 167
  • 1
  • 8
0

You want the $_SESSION['location'] value to be carried over to the home.php file, after redirection?

Make sure that $row['location'] has a value, and that session_start() has been invoked on both pages.

JustBaron
  • 2,319
  • 7
  • 25
  • 37
0

Try Checking by debugging the code like this

print_r($row);

If Yes then again do this:

echo $row['userLocation'];

Are you getting this value? Then If You want to put value into session and den redirect make sure you initialize the session first by writing session_start(); and den add the value like

$_SESSION['location]= $row['userLocation];

But make sure check are you getting value before setting session.? Better would be to solve if you update your code with print_r($row); And please stop using sql functions as they are deprecated instead use mysqli and pdo .