我花了很多时间在这上面,仍然无法使其发挥作用。
这就是registration.php的样子:
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/jquery.validate.js"></script>
<script type="text/javascript" src="/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#form_reg").validate({
rules:{
"reg_login":{
required:true,
minlength:4,
maxlength:15,
remote:{
type:"post",
url:"/reg/check_login.php"
}
},
"reg_pass":{
required:true,
minlength:4,
maxlength:15
}
},
messages:{
"reg_login":{
required:"Enter login!",
minlength:"From 4 to 15 symbols!",
maxlength:"From 4 to 15 symbols!",
remote:"Login is already in use!"
},
"reg_pass":{
required:"Enter password!",
minlength:"From 4 to 15 symbols!",
maxlength:"From 4 to 15 symbols!"
}
},
submitHandler:function(form){
$(form).ajaxSubmit({
success:function(data){
if (data == 'true'){
$("#block-form-reg").fadeOut(300, function(){
$("#reg_message").addClass("reg_message_good").fadeIn(400).html("You have been registered!");
$("#form_submit").hide();
)};
}else{
$("#reg_message").addClass("reg_message_error").fadeIn(400).html(data);
}
}
});
}
});
});
</script>
这是handler_reg.php
<?php
session_start();
include_once("../include/db_connect.php");
include_once("../functions/functions.php");
$error = array();
$login = strtolower(clear_string($_POST["reg_login"]));
$pass = strtolower(clear_string($_POST["reg_pass"]));
if(strlen($login) < 4 or strlen($login) > 15){
$error[] = "Login must contain from 4 to 15 symbols";
}else{
$result = mysql_query("SELECT login FROM reg WHERE login = '$login'", $link);
if(mysql_num_rows($result) > 0){
$error[] = "Login is already in use!";
}
}
if(strlen($pass) < 4 or trlen($pass) > 15) {$error[] = "Password must contain from 4 to 15 symbols";}
if(count($error)){
echo implode('<br/>',$error);
}else{
$pass = md5($pass);
$pass = strrev($pass);
$pass = "9nm2rv".$pass."2yo6z";
mysql_query("INSERT INTO reg_user(login, pass)
VALUES(
'".$login."',
'".$pass."'
)", $link);
echo 'true';
}
?>
最后一个 - check_login.php:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
include_once("../include/db_connect.php");
include_once("../functions/functions.php");
$login = clear_string($_POST["reg_login"]);
$result = mysql_query("SELECT login FROM reg WHERE login='$login'", $link);
if(mysql_num_rows($result) > 0){
echo 'false';
}else{
echo 'true';
}
}
?>
我在db中使用login:admin和pass:admin创建了一个用户。当我按下提交时使用login:admin并传递:user告诉我
Notice: Undefined index: reg_pass in /home/students/babae3ap/website/reg/handler_reg.php on line 9
Password must contain from 4 to 15 symbols.
当我登录时:用户并传递:admin -
Notice: Undefined index: reg_pass in /home/students/babae3ap/website/reg/handler_reg.php on line 9
Login is already in use!
Password must contain from 4 to 15 symbols
有没有人遇到过这种问题?
答案 0 :(得分:1)
代码中的拼写错误:
if(strlen($pass) < 4 or trlen($pass) > 15) {$error[] = "Password must contain from 4 to 1
到
if(strlen($pass) < 4 or strlen($pass) > 15) {$error[] = "Password must contain from 4 to 1