im just starting to learn php. im working on a basic login/user registration form and it works fine on localhost, but after i uploaded it to my server i get this error messag when i input correct login info:
Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in D:\Hosting\8927 368\html\EKMN\l ogin.php on line 53
The username you entered was not found.
here is my code:
Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in D:\Hosting\8927 368\html\EKMN\l ogin.php on line 53
The username you entered was not found.
here is my code:
Code:
<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>username Login</title>
</head>
<body>
<?php
if($username && $userid){
echo "Hey <b>$username</b>, you're already logged in! <a href='./member.php'>click here</a> for member page";
}
else{
$form = "<form action='./login.php' method='POST'>
<table>
<tr>
<td>Username</td>
<td><input type='text' name='username' /></td>
</tr>
<tr>
<td>Password</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='loginbtn' value='login' /></td>
</tr>
<tr>
<td><a href='./register.php'>Register</a></td>
<td><a href='./forgotpass.php'>Forgot your password?</a></td>
</tr>
</table>
</form>";
if ($_POST['loginbtn']){
$username = $_POST ['username'];
$password = $_POST['password'];
if ($username){
if($password){
require("connect.php");
$password = md5(md5("nt4ui2t".$password."gj4h3h"));
// make sure login info is correct
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows == 1){
$row = mysql_fetch_assoc($query);
$dbid = $row['userid'];
$dbuser = $row['username'];
$dbpass = $row['password'];
$dbactive = $row['active'];
if($password == $dbpass){
if($dbactive == 1){
// set session info
$_SESSION['userid'] = $dbid;
$_SESSION['username'] = $dbuser;
echo "Hey <b>$dbid</b> <a href='./member.php'>click here</a> for member page";
echo "<br />";
echo "userid: ".$_SESSION['userid'];
}
else
echo "You must activate your account before logging in.";
}
else
echo "Wrong password!";
}
else
echo "The username you entered was not found. $form";
mysql_close();
}
else
echo "You forgot your password! $form";
}
else
echo "You forgot your username! $form";
}
else
echo $form;
}
?>
</body>
</html>
Comment