mccoy81 Posted March 20, 2012 Share Posted March 20, 2012 Hi I am attempting to store the email provided by the customer and stored in the database in a $_SESSION variable. The problem I am having is saying that the $e is an undefined variable even though it was declared earlier in the script. Do I have to redefine the variable before storing it in a session or what could I be doing wrong? Here is the code that I am attempting to store the email in the $_SESSION variable: $q = "SELECT email FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q); $row = mysqli_fetch_assoc ($r); $_SESSION ['email'] = $row; This code is towards the bottom of the registration.php page. Where the user inputs their email and it is stored in the database. Link to comment Share on other sites More sharing options...
rob Posted March 20, 2012 Share Posted March 20, 2012 Undefined variable only means one thing, I'd re-check your syntax to make sure a value is being assigned to $e. Why are you querying the database to retrieve the email address which you already know and are using to construct the query? Why not just assign $e to the session variable? If you don't find where the error is, you'll need to post more code for people to be able to help. Link to comment Share on other sites More sharing options...
theaceofthespade Posted April 3, 2012 Share Posted April 3, 2012 Without more code, here are your three most likely possibilities I can think of: 1) $e is not actually being defined in the script 2) $e is defined somewhere inside of a conditional, so it doesn't necessarily get defined 3) The snippet you posted is inside of a function, and therefore within a different scope. 1 Link to comment Share on other sites More sharing options...
Antonio Conte Posted April 3, 2012 Share Posted April 3, 2012 Try changing to: $result = mysqli_query ($dbc, "SELECT email FROM users WHERE email='$e'"); $row = mysqli_fetch_assoc ($result); $_SESSION['email'] = $row['email']; You need to define what inside the $row array you want to use. Right now, you're assigning the whole array. 2 Link to comment Share on other sites More sharing options...
Recommended Posts