0

I've spent lots of time on this and still cannot make it work.

This is how registration.php looks like:

<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>

This is 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';
    }
?>

And the last one - 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';
    }
}
?>

I've created a user in db with login:admin and pass:admin. When I press submit with login:admin and pass:user it tells me

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.

And when I make login:user and pass: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

Did anyone face this kind of problem?

1
  • plus jquery doesn't appear on main page if I leave the inputs clean Commented Jan 18, 2016 at 2:32

1 Answer 1

1

spell mistake in code:

 if(strlen($pass) < 4 or  trlen($pass) > 15) {$error[] = "Password must contain from 4 to 1

to

 if(strlen($pass) < 4 or  strlen($pass) > 15) {$error[] = "Password must contain from 4 to 1
Sign up to request clarification or add additional context in comments.

3 Comments

nothing changes anyway, I'm having the same problem
You are getting a Notice there : **Notice: Undefined index: reg_pass ** Check the name and id you have used in the html form for password field
Thanks a lot! But still jquery doesn't work and doesn't redirect me to the registration.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.