Jump to content

[SOLVED] Warning: mysql_fetch_array(): supplied argument is not a valid MyS....


nathanmaxsonadil

Recommended Posts

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>";
}
}
}
}
?>

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

$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);

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.