是的,我已经确认查询SELECT * FROM mbgeust WHERE user_name = '{$name}' AND user_pass = SHA1('{$pass}')
返回了一个结果,但它返回说“显示行 0 - 0(总共 1 行,查询耗时 0.0005 秒)”,mysql_num_rows($mysql)
尽管查询返回一行,但不是第 0 - 1 行,因为返回 0这是我的整个代码
<?php
session_start();
include './inc/sql.php';
if(!isset($_SESSION['loggedin'])){
if(isset($_POST['submit'])){
$name = mysql_real_escape_string($_POST['username']);
$pass = mysql_real_escape_string($_POST['password']);
sql_start();
$mysql = mysql_query("SELECT * FROM mbgeust WHERE user_name = '{$name}' AND user_pass = SHA1('{$pass}')")
or die ("Error: ". mysql_error(). " with query ". $mysql);
if(mysql_num_rows($mysql) == 1){
$_SESSION['loggedin'] = TRUE;
$_SESSION['name'] = $name;
header('refresh:3; URL = /');
die('You are now logged in!');
}
else{
header('refresh:3; URL = /');
die ('Password was probably incorrect!');
}
sql_stop();
}
echo "<form action='./' method='POST'>
Username: <br/>
<input type='text' name='username' /><br/>
Password: <br/>
<input type='password' name='password' /><br/>
<input type='submit' name='submit' value='Login'/>
</form>";
}
else {
include 'main.php';
}
?>
和 sql.php
<?php
function sql_start(){
global $con;
$con = mysql_connect("mackinnonsbakery.co.uk.mysql","mackinnonsbaker","UE9ux3cZ")
or die('Could not connect: ' . mysql_error());
mysql_select_db("mackinnonsbaker", $con)
or die('Could not connect: ' . mysql_error());
}
function sql_stop(){
global $con;
mysql_close($con);
}
?>