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"; ?> 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."'"; 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. 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. 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
Archived
This topic is now archived and is closed to further replies.