vajona Posted November 21, 2010 Share Posted November 21, 2010 I'm not sure what i have done wrong here... all it says is "Query was empty" <?php SESSION_START(); ?> //some html <?php if($_SESSION['email']){ $mysql = "SELECT id,firstname FROM users WHERE 'id'='".$_SESSION['email']."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ session_destroy(); echo"Please <a href=\"/index.html\">Login</a> or <a href=\"/register.php\">Join Us.</a>"; }else{ $row = mysql_fetch_assoc($res); echo "welcome back, <a href=\"./index.php?act=profile&id=".$row['id']."\">".$row['firstname']."</a>\n"; } }else { echo"Please <a href=\"/index.html\">Login</a> or <a href=\"/register.php\">Join Us.</a>"; } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 Change the single quotes around 'id' to backticks `id` Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 Changed to `id` , but I'm still getting the error. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 echo $mysql and post the exact error Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 You have the wrong variable name here $mysql = "SELECT id,firstname FROM users WHERE 'id'='".$_SESSION['email']."'"; $res = mysql_query($sql) or die(mysql_error()); Use either $mysql or $sql, but not both. Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 well every time i use only sql or mysql it logs me out. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 Then you have another problem, but the code above, you are referencing a variable that is empty. Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 true, why would it log me out though? it's the same session i have been using Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 If it logs you out, then if(mysql_num_rows($res) == 0){ must be true. So see why that is true. Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 Ya, i am really confused because the results for the id for that session isn't 0. Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 If i change to $sql = "SELECT * FROM users WHERE `id`='specific number'"; it works. why isn't the session working here? Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 Is your $_SESSION['email'] a real email or a ID? Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 i believe it is real. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 Not sure what you mean "you believe".. echo it and see what it is. Echo your query. Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 Are you asking me if the session tests email=pass to have access to a page? if so than yes it does. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 No, Echo This $mysql = "SELECT id,firstname FROM users WHERE 'id'='".$_SESSION['email']."'"; echo $mysql; exit; Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 SELECT id,firstname FROM users WHERE 'id'='name@blah.edu' i received the logged in email. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 now copy and past that into PHPMYADMIN and run it as a query. Also, you still have the single quotes in there you need to remove. Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 update: i changed my script to $mysql = "SELECT * FROM users WHERE `email`=".$_SESSION['email'].""; and when i echo it out i get SELECT * FROM users WHERE `id`=name@blah.edu when i go to PHPMYADMIN and run it as a query i get #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@blah.edu LIMIT 0, 30' at line 1 however; if i simply put " " around the email in the query window SELECT * FROM users WHERE `email` = "name@blah.edu" gives me the correct value which is greater than 0 so my question now is how do i get it to look like that when i echo it out. i really hope that makes sense also i would like to thank you for helping. i know it's like pulling teeth. i am trying my hardest to learn everything i can about how to script. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 $mysql = "SELECT * FROM users WHERE `email` = '".$_SESSION['email']."'"; Quote Link to comment Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 Thank you so much guys. It is working now. To bad you don't live around me id take you out for food to properly thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.