1

I have a form where users enter details on themselves (including email). The data is stored and then an AUTO_INCREMENT column assigns a unique ID for the user.

I want to use this unique ID as a session variable so that I can track the users progress on the site.

This is what I have at the moment and its not working:

$qry = "SELECT * FROM user_responses WHERE email='$email'";

$result = mysqli_query($qry);

$member = mysqli_fetch_assoc($result);

$_SESSION['SESS_USERID'] = $member['userid'];

echo $_SESSION['SESS_USERID'];

session_write_close();

I think that I've selected a row in the tbl where the email address is the same as what has just been processed $email is the sanitised id for the email text input. The I've run it to store it into $result. I fetch the array for it and then assign the userid.

Its not working because I get this error:

( ! ) Notice: Undefined variable: _SESSION in C:\wamp\www\bootstrap\instructions.php on line 36

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119

1 Answers1

0

Make sure that you have session_start(); at the top of you PHP code, then you will be able to use $_SESSION[]

<?php
    session_start();
    echo $_SESSION['my_session'];
?>
Sayed
  • 1,022
  • 3
  • 12
  • 27