elis Posted December 3, 2008 Share Posted December 3, 2008 I need to perform a mysql query with a variable stored in a session - so far, it hasn't worked. It's not something I've ever needed to do before so I'm not sure what I'm doing incorrectly. (the session syntax is different due to the variant coding used) Below is a brief snippet of what I used. <?php $username = $session->get('s_username'); $sql = "SELECT * FROM employees where username = $username"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/135399-solved-query-a-session-variable/ Share on other sites More sharing options...
DeanWhitehouse Posted December 3, 2008 Share Posted December 3, 2008 your query is wrong, use or die(mysql_error()); to find these things out, it should be $sql = "SELECT * FROM employees where username = '$username'"; or $sql = "SELECT * FROM employees where username = '".$username."'"; Quote Link to comment https://forums.phpfreaks.com/topic/135399-solved-query-a-session-variable/#findComment-705224 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 <?php $username = $session->get('s_username'); $sql = "SELECT * FROM employees where username = '$username'"; ?> Assuming your session class works, you need single quotes around the variable when checking against mysql. Quote Link to comment https://forums.phpfreaks.com/topic/135399-solved-query-a-session-variable/#findComment-705227 Share on other sites More sharing options...
elis Posted December 3, 2008 Author Share Posted December 3, 2008 I see, that fixed it. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/135399-solved-query-a-session-variable/#findComment-705233 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.