0

I am a little rusty on PHP. What I would like to do is save 2 variables to be used across my project. I would like to save the email and the password from my login page to be used later on to Parse my database on Parse.com.

Using reference link: [http://php.net/manual/en/book.session.php]


SOLVED, thank you @Fred -ii- for your help and explanations!

Login file:

try{

$query = new ParseQuery("Clients");
$query->equalTo("email", "$email");
$query->equalTo("password","$password");
$results = $query->find();

} catch(Exception $e){
echo $e->getMessage();

}
if(count($results)==1){
session_start();
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
 header("Location: http://localhost/ClientPortal/mainMenu.php");
}

mainMenu file:

   session_start();
   $email = $_SESSION['email'];
   $password = $_SESSION['password']; //* fixed spelling error (used to be 'passowrd')
   session_commit();

try{

   $query = new ParseQuery("Clients");
   $query->equalTo("email", "$email");
   $query->equalTo("password","$password");
   $results = $query->find();

   } catch(Exception $e){
  echo $e->getMessage();

   }

if(count($results)==1){
echo "<p align=center>1 correct row</p>";
}
else{
 echo "<p align=center>NO correct rows</p>";
}
14
  • 3
    Typo $_SESSION['passowrd']? If not, do $_SESSION['password'] Commented Aug 7, 2014 at 18:39
  • Sidenote: If you want valid HTML, change <p align=center> to <p align=\"center\"> Commented Aug 7, 2014 at 18:41
  • You are amazing!!! But I have an additional question for you, it is running pretty slow. Can I use session_close() after I use my sessions so that it works faster? Commented Aug 7, 2014 at 18:42
  • 2
    You're welcome. That's what years of being a (past) text editor for a publishing house paid off ;) Commented Aug 7, 2014 at 18:43
  • 1
    To answer your second question question; yes I imagine it would. However it's session_write_close() and not session_close() if that's the actual function you were wanting to use, doesn't exist. Commented Aug 7, 2014 at 18:46

1 Answer 1

1

Thank you @Fred -ii- for helping me solve this!!!

Login file:

try{

$query = new ParseQuery("Clients");
$query->equalTo("email", "$email");
$query->equalTo("password","$password");
$results = $query->find();

} catch(Exception $e){
echo $e->getMessage();

}
if(count($results)==1){
session_start();
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
 header("Location: http://localhost/ClientPortal/mainMenu.php");
}

mainMenu file:

session_start();
$email = $_SESSION['email'];
$password = $_SESSION['password']; //* fixed spelling error (used to be 'passowrd')
session_commit();

try{

  $query = new ParseQuery("Clients");
  $query->equalTo("email", "$email");
 $query->equalTo("password","$password");
 $results = $query->find();

 } catch(Exception $e){
 echo $e->getMessage();

 }

if(count($results)==1){
echo "<p align=center>1 correct row</p>";
 }
 else{
 echo "<p align=center>NO correct rows</p>";
}
Sign up to request clarification or add additional context in comments.

3 Comments

It's no biggie really. Don't get me wrong, I'm not in this for the points, although they do help in regards to reputation. I posted this comment but didn't get an answer. People might get the wrong impression if/when they visit the question. There are some out there who take Stack just a wee-bit too serious for my taste. ;)
I feel the same way. I am just trying to learn. I made sure to put your name above the answer so you get credit for your help.
Yes I saw that, thanks and I was glad to help. Yet as I said also; if it's been solved, you shouldn't edit your question's code with the corrected one. I appreciate the mention, and glad that the matter got resolved, cheers - Enjoy coding :) - I +1 btw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.