当用户输入没有用户名或密码时,我无法回显页面,这是因为我的countreturnedrows()== 0行。任何解决方案都将非常感谢。
<?php
ini_set("error_reporting",E_ALL & ~E_NOTICE);
ini_set("display_errors",1);
include_once $_SERVER['DOCUMENT_ROOT'] . "/flourish/toinclude.php";
$mydb=new fDatabase("mssql", "finance","mytest","","ISOMTEACHING5\INFOSYS280",61495);
$result = $mydb->query("SELECT * FROM person WHERE personname=%s AND password=%s", $_POST['username'], $_POST['password']);
if($result->countReturnedRows() == 0)
{
echo "Sorry, but your username and password that you have entered doesn't exist.";
}
else
{
$fetchresult = $result->fetchRow();
$userid = $fetchresult['username'];
$isadmin = $fetchresult['admin'];
header("location:mainpage.php");
}
?>
答案 0 :(得分:0)
将整个事物包装在另一个if语句中:
if ($_POST['username'] != '' || $_POST['password'] != '')
{
include_once $_SERVER['DOCUMENT_ROOT'] . "/flourish/toinclude.php";
$mydb=new fDatabase("mssql", "finance","mytest","","ISOMTEACHING5\INFOSYS280",61495);
$result = $mydb->query("SELECT * FROM person WHERE personname=%s AND password=%s", $_POST['username'], $_POST['password']);
if($result->countReturnedRows() == 0)
{
echo "Sorry, but your username and password that you have entered doesn't exist.";
}
else
{
$fetchresult = $result->fetchRow();
$userid = $fetchresult['username'];
$isadmin = $fetchresult['admin'];
header("location:mainpage.php");
}
}
这样,如果用户没有输入用户名或密码,它将跳过整个块。