正しいクエリSELECT * FROM mbgeust WHERE user_name = '{$name}' AND user_pass = SHA1('{$pass}')
が結果を返すことを確認しましたが、「Showing rows 0 - 0 ( total 1, Query takes 0.0005 sec)」というメッセージがmysql_num_rows($mysql)
返され、クエリが1行を返すという事実にもかかわらず、行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);
}
?>