проверка поля "Repeat password "

новобранец

Новичок
Друзья ,не могу разобраться есть форма :
HTML:
<form method="post" action="forma.php">
<p><b>Registration:</b><p>
<p><B>Login:</B></p>
    <input type="text" name="r_login" size="40" /> <?echo "<b>".$err['reg_log']."</b>";?><?echo $err['str_reg_log'];?>
<p><B>Password:</B></p>
    <input type="password" name="r_password" size="50"/><?echo "<b>".$err['reg_pass']."</b>";?><?echo $err['str_reg_pass'];?>
<p><B>Repeat Password:</B></p>
    <input type="password" name="rep_reg_password" size="50"/> <?echo "<b>".$err['the_same']."</b>";?>
<p><B>Email:</B><p>
    <input type="text" name="email" size ="50"> <?echo "<b>".$err['email']."</b>";?>
    <br/><br/>
    <input type="submit" name="confirm" size="50" value="Confirm"/>
    </form>
</body>
Сделал разнообразные проверки полей,но столкнулся с ошибкой поля повторного ввода пароля"Repeat password ";Даже если соблюдаются все ограничения ,все равно выскакивает ошибка $err['the_same'].Помогите разобраться.
PHP:
if(isset ($_POST['confirm']))
    {
        $reg_log=$_POST['r_login'];
        $reg_pass=$_POST['r_password'];
        $rep_reg_pass=$_POST['rep_reg_pass'];
        $email=$_POST['email'];
        if(!preg_match("/^[a-zA-Z0-9_-]+$/i",$reg_log)){$check=false; $err['reg_log']="*Incorect registration login Example:asd123";}
        if(strlen($reg_log)< 3 || strlen($reg_log)> 30){$check=false;$err['str_reg_log']="*Login must be more that 3 chars and less 30";}
        if(!preg_match("/^[a-zA-Z0-9]+$/i",$reg_pass)){$chek=false; $err['reg_pass']="*Incorect registration password Example:123qwe";}
        if(strlen($reg_pass) < 4 || strlen($reg_pass)>30){$check=false;$err['str_reg_pass']="*Password must be more that 4 chars and less 30";}
        if($reg_pass != $rep_reg_pass){$check=false; $err['the_same']="*password and repeat passwod must be the same";}
        if(!preg_match("/^[0-9a-z_]+@[0-9a-z_]+\.[a-z]{2,3}$/i",$email)){$check=false; $err['email']="*incorect email Example:[email protected]";}
       

    }
И если если можно еще как-то улучшить код,относительно моего уровня(новичок),то был бы вам очень признателен!
Заранее Спасибо.
 

fixxxer

К.О.
Партнер клуба
как-то улучшить код
Легко. PHPStorm, Code -> Reformat
PHP:
if (isset ($_POST['confirm'])) {
	$reg_log = $_POST['r_login'];
	$reg_pass = $_POST['r_password'];
	$rep_reg_pass = $_POST['rep_reg_pass'];
	$email = $_POST['email'];
	if (!preg_match("/^[a-zA-Z0-9_-]+$/i", $reg_log)) {
		$check = false;
		$err['reg_log'] = "*Incorect registration login Example:asd123";
	}
	if (strlen($reg_log) < 3 || strlen($reg_log) > 30) {
		$check = false;
		$err['str_reg_log'] = "*Login must be more that 3 chars and less 30";
	}
	if (!preg_match("/^[a-zA-Z0-9]+$/i", $reg_pass)) {
		$chek = false;
		$err['reg_pass'] = "*Incorect registration password Example:123qwe";
	}
	if (strlen($reg_pass) < 4 || strlen($reg_pass) > 30) {
		$check = false;
		$err['str_reg_pass'] = "*Password must be more that 4 chars and less 30";
	}
	if ($reg_pass != $rep_reg_pass) {
		$check = false;
		$err['the_same'] = "*password and repeat passwod must be the same";
	}
	if (!preg_match("/^[0-9a-z_]+@[0-9a-z_]+\.[a-z]{2,3}$/i", $email)) {
		$check = false;
		$err['email'] = "*incorect email Example:[email protected]";
	}
}
Так намного читабельнее, разве нет? И опечатки сразу заметно.
Помогите разобраться.
В таких вещах разбираются не методом пристального взгляда, а отладкой. Это можешь сделать только ты сам.
http://phpfaq.ru/debug
 

новобранец

Новичок
Легко. PHPStorm, Code -> Reformat
PHP:
if (isset ($_POST['confirm'])) {
    $reg_log = $_POST['r_login'];
    $reg_pass = $_POST['r_password'];
    $rep_reg_pass = $_POST['rep_reg_pass'];
    $email = $_POST['email'];
    if (!preg_match("/^[a-zA-Z0-9_-]+$/i", $reg_log)) {
        $check = false;
        $err['reg_log'] = "*Incorect registration login Example:asd123";
    }
    if (strlen($reg_log) < 3 || strlen($reg_log) > 30) {
        $check = false;
        $err['str_reg_log'] = "*Login must be more that 3 chars and less 30";
    }
    if (!preg_match("/^[a-zA-Z0-9]+$/i", $reg_pass)) {
        $chek = false;
        $err['reg_pass'] = "*Incorect registration password Example:123qwe";
    }
    if (strlen($reg_pass) < 4 || strlen($reg_pass) > 30) {
        $check = false;
        $err['str_reg_pass'] = "*Password must be more that 4 chars and less 30";
    }
    if ($reg_pass != $rep_reg_pass) {
        $check = false;
        $err['the_same'] = "*password and repeat passwod must be the same";
    }
    if (!preg_match("/^[0-9a-z_]+@[0-9a-z_]+\.[a-z]{2,3}$/i", $email)) {
        $check = false;
        $err['email'] = "*incorect email Example:[email protected]";
    }
}
Так намного читабельнее, разве нет? И опечатки сразу заметно.

В таких вещах разбираются не методом пристального взгляда, а отладкой. Это можешь сделать только ты сам.
http://phpfaq.ru/debug
Спасибо вам,буду пробовать.
 
Сверху