this is my login function:
function doLogin($username, $password) {
include ("global.php");
$conn = mysql_connect($DB_HOST, $DB_USER, $DB_PASS);
if (!$conn)
{
return 2;
}
mysql_select_db($dbnames[$DATABASE_MAPLESTORY]);
$result = mysql_query("SELECT * FROM `accounts` WHERE `name` = '" . $username . "'");
if (mysql_num_rows($result) < 1) {
mysql_close($conn);
return 1;
}
$row = mysql_fetch_array($result);
mysql_free_result($result);
mysql_close($conn);
if (!empty($row['salt']))
{
//Make a salted password string
$saltedstr = hash("SHA512", $password . $row['salt']);
if ($saltedstr != $row['password'])
{
return 1;
}
}
else
{
//There is no salt, probably because he/she never logged in on the game
//We will just do the regular check here
if (sha1($password) != $row['password'])
{
return 1;
}
}
//All ok! =]
session_start();
$_SESSION['id'] = $row['id'];
$_SESSION['name'] = $row['name'];
$_SESSION['loggedin'] = $row['loggedin'];
$_SESSION['lastlogin'] = $row['lastlogin'];
$_SESSION['createdat'] = $row['createdat'];
$_SESSION['birthday'] = $row['birthday'];
$_SESSION['banned'] = $row['banreason'];
$_SESSION['gm'] = $row['gm'];
$_SESSION['email'] = $row['email'];
$_SESSION['lastpwemail'] = $row['lastpwemail'];
$_SESSION['tempban'] = $row['tempban'];
$_SESSION['greason'] = $row['greason'];
$_SESSION['nxCash'] = $row['nxCash'];
$_SESSION['mPoints'] = $row['mPoints'];
$_SESSION['gTokens'] = $row['gTokens'];
$_SESSION['weblogged'] = "true";
header('Location: ' . $ROOT_PAGE);
return 0;
}
and my login section just contains this:
<?PHP
session_start();
include("globals/global.php");
include("globals/functions.php");
echo ('<h1><span>Login</h1></span>
<p></p>');
if (!empty($_POST['username']) && !empty($_POST['password']))
{
if (doLogin($_POST['username'], $_POST['password']) == 1)
{
echo "The username and password provided did not match.";
}
}
echo('<form action="');$_SERVER['PHP_SELF'];echo('" method="post">
Username: <input type="text" name="username" value=""> <br />
Password: <input type="password" name="password" value=""> <br />
<input type="image" name="submit" src="images/login.gif" alt="Login">
');
?>
now whenever I try to log in .. i keep on getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\globals\functions.php on line 35
The username and password provided did not match.
Help please?