jarv Posted February 11, 2011 Share Posted February 11, 2011 hi, I am having problems setting a session from a SQL query, please help... here is my code: $query1 = "SELECT * FROM members_copy WHERE rsUser = '$username' AND rsPass = '$password'"; $result1 = mysql_query($query1); echo "<br>".$result1['USERID']; $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['USERID']=$result1['USERID']; $_SESSION['RSTOWN']=$result1['RSTOWN']; $_SESSION['RSEMAIL']=$result1['RSEMAIL']; $_SESSION['RSUSER']=$result1['RSUSER']; no sessions are currently being set?! :-\ Quote Link to comment https://forums.phpfreaks.com/topic/227369-execute-sql-and-set-a-session/ Share on other sites More sharing options...
BlueSkyIS Posted February 11, 2011 Share Posted February 11, 2011 do you have session_start() at the top of the code? Quote Link to comment https://forums.phpfreaks.com/topic/227369-execute-sql-and-set-a-session/#findComment-1172756 Share on other sites More sharing options...
KevinM1 Posted February 11, 2011 Share Posted February 11, 2011 mysql_query only executes a query. It doesn't give you access to the result set. For that, you need to fetch the results: mysql_fetch_array or mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/227369-execute-sql-and-set-a-session/#findComment-1172757 Share on other sites More sharing options...
jarv Posted February 11, 2011 Author Share Posted February 11, 2011 ok so I changed my code to $query1 = "SELECT * FROM members_copy WHERE rsUser = '$username' AND rsPass = '$password'"; $result1 = mysql_fetch_array($query1); echo "<br>".$result1['USERID']; and now I get the following error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\mypubspace.com\wwwroot\mobile\dologin.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/227369-execute-sql-and-set-a-session/#findComment-1172762 Share on other sites More sharing options...
Maq Posted February 11, 2011 Share Posted February 11, 2011 You forgot to call mysql_query. Quote Link to comment https://forums.phpfreaks.com/topic/227369-execute-sql-and-set-a-session/#findComment-1172763 Share on other sites More sharing options...
jarv Posted February 11, 2011 Author Share Posted February 11, 2011 thankyou! Quote Link to comment https://forums.phpfreaks.com/topic/227369-execute-sql-and-set-a-session/#findComment-1172765 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.