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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/ 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` Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137389 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137390 Share on other sites More sharing options...
revraz Posted November 21, 2010 Share Posted November 21, 2010 echo $mysql and post the exact error Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137392 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137393 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137394 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137395 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 Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137396 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137399 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137402 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? Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137406 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? Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137408 Share on other sites More sharing options...
vajona Posted November 21, 2010 Author Share Posted November 21, 2010 i believe it is real. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137409 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137411 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137412 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; Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137413 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'='[email protected]' i received the logged in email. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137414 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137415 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`[email protected] 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` = "[email protected]" 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137583 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']."'"; Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137585 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. Link to comment https://forums.phpfreaks.com/topic/219349-query-was-empty/#findComment-1137613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.