我在这里做错了什么:
<?php
if (isset($_POST['submitted'])) {
$errors = array();
require_once ('mysql_connect.php');
session_start();
$username = $_POST["username"]; // This is the inputted username from the form in Login.html
$password = $_POST["password"]; // This is the inputted password from the form in Login.html
if (empty($errors)) {
$query="SELECT username FROM users WHERE username='$username' AND password='SHA($password)'";
$result = mysql_query($query);
// Mysql_num_row is counting table row
if (mysql_num_rows($result) == 1) {
$_SESSION["username"] = $username; // Creates a cookie saving the username
$_SESSION["loggedIn"] = true; // Creates a cookie saying the user is logged in
// Show thank you message
echo '<h3 style="color:green;">Thank You!</h3>
<span style="color:green;">You have been logged in.</span>';
} else {
echo '<font color="red">You could not be logged in, please make sure your username and password is correct.</font>';
foreach ($errors as $msg) {
echo " - <font color=\"red\">$msg</font><br />\n";
}
}
} else {
echo '<font color="red"><h3>Error!</h3>
The following error(s) occured:<br /></font>';
foreach ($errors as $msg) {
echo " - <font color=\"red\">$msg</font><br />\n";
}
}
}
?>
我得到一个:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /login.php on line 19
我 SHA 密码的方式也是正确的吗?