这是一个只有用户名和密码的登录表单。它运作良好,但我希望我的信息区分大小写。例如,我的数据库用户名是:David 和密码:PooPoo。虽然如果我插入用户名:daVid 和密码:PoOPOo 它会解析表单。
我的代码如下所示:
<?php
session_start();
if (isset($_SESSION["manager"])) {
header("location: index.php");
exit();
}
?>
<?php
if (isset($_POST["username"]) && isset($_POST["password"])) {
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]);
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]);
include "../storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); // query the person
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 1) { // evaluate the count
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["manager"] = $manager;
$_SESSION["password"] = $password;
header("location: index.php");
exit();
}else{
print '<script type="text/javascript">';
print 'alert("wrong info")';
print '</script>';
}
}
?>
我的验证脚本
<script type="text/javascript" language="javascript">
function validateMyForm ( ) {
var isValid = true;
if ( document.adminlogin.username.value == "" ) {
alert ( "Please enter your username" );
isValid = false;
} else if ( document.adminlogin.password.value == "" ) {
alert ( "Please enter password" );
isValid = false;
}
return isValid;
}
</script>
请问我的错误在哪里?