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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.