Does not write an error that the login is busy and that the fields are empty, always writes that they are successfully registered. In the database enters if the data is correct.
Reg.php file
<?php include("include/db_connect.php"); include("functions/functions.php"); ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/> <link href="css/reset.css" rel="stylesheet" type="text/css" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> <title>Регистрация</title> </head> <body> <div id="block-body"> <?php include("include/block-header.php"); ?> <div id="block-cont"> <form method="post" id="form_reg" action="/reg/handler_reg.php"> <p id="reg_message"></p> <div id="block-form-reg"> <div class="form-group"> <label for="inputName">Логин</label> <input type="text" class="form-control" name="reg_login" id="reg_login" placeholder="Введите Логин" /> </div> <div class="form-group"> <label for="inputPass">Пароль</label> <input type="text" class="form-control" name="reg_pass" id="reg_pass" placeholder="Введите Пароль" /> </div> <div class="form-group"> <label for="inputEmail">Email</label> <input type="email" class="form-control" name="reg_email" id="reg_email" placeholder="Введите Email" /> </div> <input type="submit" name="reg_submit" id="reg_submit" value="Регистраиця" /> </div> </form> </div> <?php include("include/block-footer.php"); ?> <script type="text/javascript" src="/js/shop-script.js"></script> <script type="text/javascript" src="/js/jquery.form.js"></script> <script type="text/javascript" src="/js/jquery-3.1.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script> <script> $("#form_reg").submit(function(event) { event.preventDefault(); // прерываем отправку формы var data = $('#form_reg').serialize(); $.ajax({ type: "POST", url:"/reg/handler_reg.php", data:data, error:function(){ $("#reg_message").addClass("reg_mess_error").fadeIn(400).html(data); }, beforeSend: function() { $("#reg_message").html('Загрузка...'); }, success: function(html){ $("#block-form-reg").fadeOut(300); $("#reg_message").addClass("reg_mess_good").fadeIn(400).html("Вы успешно зарегистрированы!"); } }); return false; }); </script> </body> </html> File handler_reg.php
session_start(); include("../include/db_connect.php"); include("../functions/functions.php"); $error = array(); $login = iconv("UTF-8", "cp1251",strtolower(clear_string($_POST['reg_login']))); $pass = iconv("UTF-8", "cp1251",strtolower(clear_string($_POST['reg_pass']))); $email = iconv("UTF-8", "cp1251",clear_string($_POST['reg_email'])); if (strlen($login) < 5 or strlen($login) > 15) { $error[] = "Логин должен быть от 5 до 15 символов!"; } else { $result = mysql_query("SELECT login FROM reg_user WHERE login = '$login'",$link); If (mysql_num_rows($result) > 0) { $error[] = "Логин занят!"; } } if (strlen($pass) < 7 or strlen($pass) > 15) $error[] = "Укажите пароль от 7 до 15 символов!"; if (!preg_match("/^(?:[a-z0-9]+(?:[-_.]?[a-z0-9]+)?@[a-z0-9_.-]+(?:\.?[a-z0-9]+)?\.[az]{2,5})$/i",trim($email))) $error[] = "Укажите корректный email!"; if (count($error)) { echo implode('<br />',$error); }else { $pass = md5($pass); $pass = strrev($pass); $pass = "9nm2rv8q".$pass."2yo6z"; $ip = $_SERVER['REMOTE_ADDR']; mysql_query(" INSERT INTO reg_user(login,pass,email) VALUES( '".$login."','".$pass."','".$email."')",$link); echo 'Регистрация прошла успешно! <a href="index.php">Перейти на главную страницу.</a> '; } ?>
handler_reg.phpwhere? - Naumovif (count($error))- what are you checking here? - Dmitriy Kondratiuk