我知道有类似的线程,我已经查看了这些线程,尽管它们似乎都不适合我。
首先,我想指出的是,这是一个简单的大学作业,不是一个实际的网站,我不担心"安全"或任何东西。
其次,我的数据库是由'username' 'password' and 'admin', admin being 0 or 1
组成的。
我需要帮助的是,如果管理员值为 1,而不是 0,则让用户重定向到 'hit-counter.php'
。
目前,无论管理员值如何,它们总是转到'index_loginsuccesful.php'
。(或者'index_loginfailed.php'
用户名/密码是否错误)
有什么想法吗?
<?php
$conn = mysql_connect ("localhost", "root","");
mysql_select_db("a_blub",$conn);
$result=mysql_query("SELECT password FROM user WHERE username = '$_POST[theusername]'",$conn);
$rows=mysql_fetch_array($result);
if($_POST['thepassword'] == $rows[0])
{
if ($_POST['admin'] == 1)
Header("location:hit-counter.php");
else
Header("location:index_loginsuccesful.php");
}
else
{
Header("location:index_loginfailed.php");
} ?>
你能试试这个吗?
$conn = mysql_connect ("localhost", "root","");
mysql_select_db("a_blub",$conn);
$result = mysql_query("SELECT password FROM user WHERE username = '".mysql_real_escape_string($_POST['theusername'])."' LIMIT 1", $conn);
$row = mysql_fetch_assoc($result);
if ($_POST['thepassword'] == $row['password']) {
if ($row['admin'] == 1) {
header("Location: hit-counter.php");
exit;
} else {
header("Location: index_loginsuccesful.php");
exit;
}
} else {
header("Location: index_loginfailed.php");
exit;
}
如果要
根据数据库中的数据重定向到不同位置,则需要将1
与您从数据库中返回的数据进行比较,而不是$_POST
其中包含从表单提交的数据。您还需要选择包含该数据的列以及password
。