nathanmaxsonadil Posted August 17, 2007 Share Posted August 17, 2007 I'm getting this error when I enter my data into login.php Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.../login.php on line 66 What's the matter? here's the part that causes the problem else { $_POST['password'] = md5($_POST['password']); $checklogin2 = mysql_query("SELECT * FROM users WHERE username = '{$_POST['username']}'"); $checklogin = mysql_query($checklogin2); while ($row = mysql_fetch_array($checklogin, MYSQL_ASSOC)) { if (mysql_num_rows($checklogin) !== $_POST['username']) { forum("Your username is wrong!<br/>"); include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); }else if ($row['password'] !== $_POST['password']){ forum("Your password is wrong!<br/>"); include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); }else if($row['password'] == $_POST['password'] && $row['username'] == $_POST['username']) { $_SESSION['username'] == $row['username']; $_SESSION['email'] == $row['email']; $_SESSION['loggedin'] == true; $_SESSION['points'] == $row['points']; echo "<script type='text/javascript'> <!-- window.location = 'http://www.swapinvites.com/' //--> </script>"; } } } } here's my login script <?php $title = 'Swap Invites - Login'; include 'header.php'; include('./config.php'); $divs = '<div style="clear: both;"> </div></div>'; function forum($text) { echo "<div id='content'> <div id='columnA'><h2>Login</h2>"; echo $text; echo "<form method='post'> username:<br/> <input type='text' name='username' /> <br /> password:<br/><input type='password' name='password' /> <br/> <input type='hidden' name='hidden' value='hidden'> <input type='submit' value='Submit' /> </form></div> "; } if(empty($_POST['hidden'])) { forum(""); include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); } if(isset($_POST['hidden'])) { $_POST['username'] = mysql_real_escape_string($_POST['username']); $_POST['password'] = mysql_real_escape_string($_POST['password']); $_POST['hidden'] = mysql_real_escape_string($_POST['hidden']); $_POST['username'] = htmlentities($_POST['username']); $_POST['password'] = htmlentities($_POST['password']); $_POST['hidden'] = htmlentities($_POST['hidden']); if(strlen($_POST['username']) > 16) { forum("you username is too long! it has to be less than 16 characters!<br/>"); echo 'you username too long '; include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); } else if(strlen($_POST['username']) < 6) { forum("you username is too short! it has to be more than 6 characters!<br/>"); include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); }else if(strlen($_POST['password']) > 25) { forum("you password is too long! it has to be less than 25 characters!<br/>"); include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); }else if(strlen($_POST['password']) < 6) { forum("you password is too short! it has to be more than 6 characters!<br/>"); include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); }else { $_POST['password'] = md5($_POST['password']); $checklogin2 = mysql_query("SELECT * FROM users WHERE username = '{$_POST['username']}'"); $checklogin = mysql_query($checklogin2); while ($row = mysql_fetch_array($checklogin, MYSQL_ASSOC)) { if (mysql_num_rows($checklogin) !== $_POST['username']) { forum("Your username is wrong!<br/>"); include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); }else if ($row['password'] !== $_POST['password']){ forum("Your password is wrong!<br/>"); include 'sidebar.php'; echo $divs; include 'footer.php'; exit(); }else if($row['password'] == $_POST['password'] && $row['username'] == $_POST['username']) { $_SESSION['username'] == $row['username']; $_SESSION['email'] == $row['email']; $_SESSION['loggedin'] == true; $_SESSION['points'] == $row['points']; echo "<script type='text/javascript'> <!-- window.location = 'http://www.swapinvites.com/' //--> </script>"; } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/ Share on other sites More sharing options...
sasa Posted August 17, 2007 Share Posted August 17, 2007 for debug try change line $checklogin = mysql_query($checklogin2) ; to $checklogin = mysql_query($checklogin2) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/#findComment-327123 Share on other sites More sharing options...
nathanmaxsonadil Posted August 17, 2007 Author Share Posted August 17, 2007 lol now i get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/#findComment-327126 Share on other sites More sharing options...
sasa Posted August 17, 2007 Share Posted August 17, 2007 ok change line $checklogin2 = mysql_query("SELECT * FROM users WHERE username = '{$_POST['username']}'"); to echo '$checklogin2 = ', $checklogin2 = mysql_query("SELECT * FROM users WHERE username = '{$_POST['username']}'"); to see how your SQL string look like 2nd try to print_r($_POST['username']); before this line Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/#findComment-327137 Share on other sites More sharing options...
nathanmaxsonadil Posted August 17, 2007 Author Share Posted August 17, 2007 $checklogin2 = Resource id #6You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/#findComment-327153 Share on other sites More sharing options...
AndyB Posted August 17, 2007 Share Posted August 17, 2007 $checklogin2 = mysql_query("SELECT * FROM users WHERE username = '{$_POST['username']}'"); $checklogin = mysql_query($checklogin2); makes no sense. I assume what you wished you had used is: $checklogin2 = "SELECT * FROM users WHERE username = '". $_POST['username']. "'"; $checklogin = mysql_query($checklogin2); Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/#findComment-327159 Share on other sites More sharing options...
nathanmaxsonadil Posted August 17, 2007 Author Share Posted August 17, 2007 that works just wondering why did my code not work? Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/#findComment-327168 Share on other sites More sharing options...
AndyB Posted August 17, 2007 Share Posted August 17, 2007 just wondering why did my code not work? Take a look at your code (the bit I posted). $checklogin2 is a query resource not a query string. mysql_query() takes a query string and returns a query resource. Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/#findComment-327176 Share on other sites More sharing options...
nathanmaxsonadil Posted August 17, 2007 Author Share Posted August 17, 2007 lol Quote Link to comment https://forums.phpfreaks.com/topic/65508-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mys/#findComment-327181 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.