2014-09-17 2 views
-1

여기에 내 코드가 있습니다. 난 그냥 내 웹 사이트에 확인 암호 텍스트 필드를 추가하고 싶습니다. 그러나 내가 if($_POST['password'] != $_POST['confirm_password']){ $message = "Your passwords did not match."; }을 넣는다면. 그것은 단지 암호가 일치하지 않았 음을 보여 주지만 여전히 데이터베이스에 있습니다. 암호 및 확인 암호 텍스트 필드가 일치하지 않으면 오류를 알리는 대화 상자가 나타납니다. 완전하고 정확하지 않으면 데이터베이스에 저장되지 않습니다.'비밀번호 - 비밀번호 확인'오류

여기 내 PHP 코드입니다.

<?php 

if(isset($_POST["register"])){ 

if(!empty($_POST['full_name']) && !empty($_POST['email']) && !empty($_POST['username']) && !empty($_POST['password'])) { 
    $full_name=$_POST['full_name']; 
    $email=$_POST['email']; 
    $username=$_POST['username']; 
    $password=$_POST['password']; 
    $confirm_password = $_POST['confirm_password']; 


    $query=mysql_query("SELECT * FROM usertbl WHERE username='".$username."'"); 
    $studnoquery=mysql_query(""); 





    $numrows=mysql_num_rows($query); 

    $passconfirm=($_POST['password'] != $_POST['confirm_password']); 

    if($numrows==0) 

    { 


    $sql="INSERT INTO usertbl 
      (full_name, email, username,password) 
      VALUES('$full_name','$email', '$username', '$password')"; 

    $result=mysql_query($sql); 

    if($result){ 
    $message = "Account Successfully Created"; 
    } else { 
    $message = "Failed to insert data information!"; 
    } 
    } 

    //if numrows is greater than 1 
    else { 
    $message = "That username already exists! Please try another one!"; 
    } 
} 


else { 
    $message = "All fields are required!"; 
} 
} 
?> 

은 내가 if($_POST['password'] != $_POST['confirm_password'])이 정확하다고 생각하지만 난 어디에 내 코드에 넣어하는 힘든 시간을 보내고 있습니다. 감사. 도와주세요.

+0

'$ passconfirm'을 사용하지 마십시오. 사실, 당신이하는 유일한 오류 검사는 사용자 이름이 있는지 확인하는 것입니다. 또한 쓸모없는 API를 사용하고 있으며 SQL 인젝션에 대해 광범위하게 개방되어 있습니다. –

+0

당신의 코드는'$ passconfirm = ($ _ POST [ 'password']! = $ _POST [ 'confirm_password']);''($ _ POST [ 'password'] ...' 거짓으로. –

+0

나는 그것을 알고있다.하지만 난 아직도 노력하고있어. 내가 물어 보려고하는 것은'if ($ _ POST [ 'password']! = $ _POST [ 'confirm_password'])'' 코드. 내가 쓴다면, "암호가 일치하지 않는다"라는 메시지가 내 데이터베이스에 여전히 삽입되어있다. 제발 도와주세요. 내 코드를 편집하십시오. – Kerv

답변

0

여기에 업데이트 된 코드가 있습니다. 변수는 $error입니다. 암호와 확인 암호가 일치하지 않으면 $error 변수의 값은 1이되고 그렇지 않으면 null이됩니다.

<?php 

if(isset($_POST["register"])){ 

if(!empty($_POST['full_name']) && !empty($_POST['email']) && !empty($_POST['username']) && !empty($_POST['password'])) { 
    $full_name=$_POST['full_name']; 
    $email=$_POST['email']; 
    $username=$_POST['username']; 
    $password=$_POST['password']; 
    $confirm_password = $_POST['confirm_password']; 


    $query=mysql_query("SELECT * FROM usertbl WHERE username='".$username."'"); 
    $studnoquery=mysql_query(""); 





    $numrows=mysql_num_rows($query); 
    $error = ''; 
    if($_POST['password'] != $_POST['confirm_password']) { 
      $message = "Your passwords did not match."; 
      $error = 1; 
    } 
    $passconfirm=($_POST['password'] != $_POST['confirm_password']); 

    if($numrows==0 && $error=='') 

    { 


    $sql="INSERT INTO usertbl 
      (full_name, email, username,password) 
      VALUES('$full_name','$email', '$username', '$password')"; 

    $result=mysql_query($sql); 

    if($result){ 
    $message = "Account Successfully Created"; 
    } else { 
    $message = "Failed to insert data information!"; 
    } 
    } 

    //if numrows is greater than 1 
    else { 
    $message = "That username already exists! Please try another one!"; 
    } 
} 


else { 
    $message = "All fields are required!"; 
} 
} 
?> 
+2

변경 한 내용을 설명하지 않고 OP의 코드를 회피하지 마십시오. –

+0

#Marc 귀하의 의견에 따라 추가 코드를 설명했습니다. – Nikul

+0

. 그것은 항상 "그 사용자 이름이 이미 존재합니다! 다른 것을 시도하십시오!"; 그리고 여전히 암호가 보이지 않는지 확인하십시오. – Kerv