fohanlon Posted February 27, 2009 Share Posted February 27, 2009 Hi Guys I have a mysql query that checks a table for a match for a userid and a sesion variable. I store this when the user logs on and wipe it when they log out Heres the issue. When I then try to log in again it returns my message about already being logged in even though I would expect the mysq;l query to return 0 it always returns 1. Heres the code: $result = mysql_query("SELECT COUNT(*) FROM log_participants WHERE AccountID = '$accid' AND Course = '$course' AND SessionID = '" . mysql_real_escape_string(session_id()) . "'"); if(!$result) echo mysql_error(); echo "Result is " . mysql_num_rows($result); Result is always 1. Any ideas? Thanks, fergal. Link to comment https://forums.phpfreaks.com/topic/147241-session-variable-check-in-mysql-causing-problems/ Share on other sites More sharing options...
teng84 Posted February 27, 2009 Share Posted February 27, 2009 yes result will be 1 why? because you will have this as your result COUNT(*) = 0 ; so you have result one result but the value of the rsult is 0 and rephrase your code kinda wrong though Link to comment https://forums.phpfreaks.com/topic/147241-session-variable-check-in-mysql-causing-problems/#findComment-772950 Share on other sites More sharing options...
fohanlon Posted February 28, 2009 Author Share Posted February 28, 2009 So what you are saying it the COUNT(*) is 1 becuase the returned result is 0 i.e it is counting an empty result as 1. How could I fix the code? Thanks, fergal. Link to comment https://forums.phpfreaks.com/topic/147241-session-variable-check-in-mysql-causing-problems/#findComment-772952 Share on other sites More sharing options...
teng84 Posted February 28, 2009 Share Posted February 28, 2009 replace count(*) with the specific fields your querying and use your Primary keys eg ID so you have select field from tablename where etcc.. Link to comment https://forums.phpfreaks.com/topic/147241-session-variable-check-in-mysql-causing-problems/#findComment-772958 Share on other sites More sharing options...
fohanlon Posted February 28, 2009 Author Share Posted February 28, 2009 Thanks very much - that solved the problem. Although i'd still like to know what count(*) was doing? Must look at the man pages for php. Fergal. Link to comment https://forums.phpfreaks.com/topic/147241-session-variable-check-in-mysql-causing-problems/#findComment-772960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.