mtayloronline Posted March 2, 2011 Share Posted March 2, 2011 Hi Guys, Im new here, Can someone please help me and tell me why my PHP code isn't working :/ <?php session_start(); $sql = mysql_connect('localhost', 'putwriter_login', 'MyPassHere'); if(!$sql){ die(mysql_error()); } mysql_select_db('putwriter_college'); $user = mysql_real_escape_string($_POST['user']); $pass = mysql_real_escape_string($_POST['password']); $sqlSel = mysql_query("SELECT * FROM `putwriter_college`.`Login` WHERE `EmailAddress`=$user AND `Password`=$pass LIMIT 1;"); while($row = mysql_fetch_assoc($sqlSel)){ echo 'Im probably not here'; if(($row['EmailAddress'] == $user) && ($row['Password'] == $pass)){ $_SESSION['loggedIn'] = md5('someSessId'); echo "<meta http-equiv='refresh' content='2;url=./home.php'>"; }else{ die('FAIL'); } } ?> This is what I get : Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/putwriter/domains/putwriter.co.uk/public_html/login.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/229373-my-php-login/ Share on other sites More sharing options...
bh Posted March 2, 2011 Share Posted March 2, 2011 Your select query isnt valid. $sqlSel = mysql_query("SELECT * FROM `putwriter... Whats your putwriter_college.Login table structure? Quote Link to comment https://forums.phpfreaks.com/topic/229373-my-php-login/#findComment-1181850 Share on other sites More sharing options...
DarkMantis Posted March 2, 2011 Share Posted March 2, 2011 My table structure is as follows: ID (int 7) EmailAddress (varchar 255) Password (varchar 255) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/229373-my-php-login/#findComment-1181852 Share on other sites More sharing options...
bh Posted March 2, 2011 Share Posted March 2, 2011 Your query structure is ok, it might be one of the variables in the query... $user = mysql_real_escape_string($_POST['user']); $pass = mysql_real_escape_string($_POST['password']); var_dump($user); var_dump($pass); Debug a bit, lets see the variables content... Both are string? Quote Link to comment https://forums.phpfreaks.com/topic/229373-my-php-login/#findComment-1181853 Share on other sites More sharing options...
DarkMantis Posted March 2, 2011 Share Posted March 2, 2011 Hey, Both are string I've got that error sorted now it just continously loads without forwarding me to the second page. Quote Link to comment https://forums.phpfreaks.com/topic/229373-my-php-login/#findComment-1181857 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2011 Share Posted March 2, 2011 If they're both string values, they need to be quoted in the query string. . . . `EmailAddress`= '$user' AND `Password`= '$pass' . . . Quote Link to comment https://forums.phpfreaks.com/topic/229373-my-php-login/#findComment-1181865 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.