2013-08-08 2 views
1

다음은 내 웹 사이트에서 register.php에 대한 코드입니다. 이 코드는 사용자가 내 웹 사이트에 등록하고, 제출 버튼을 클릭하여 사용자 이름, 이메일, 비밀번호 등을위한 MySQL 항목을 생성 할 수 있도록합니다. 버튼의 이름은 "reg"이고 $ _POST를 사용합니다. 제출 버튼을 클릭하면 php는 여러 if 문을 실행하여 사용자가 입력 한 정보가 유효하고 사전에 존재하지 않는지 확인합니다. 사용자가 존재하거나 제출시 오류가 발생하면 PHP 변수 $ errormessage를 설정하고이를 반향 출력합니다. 지금은 내 SUBMIT 버튼이 눌려진 것처럼 작동하지 않습니다. 오류 메시지가 없으며 SQL 행이 삽입되지 않고 아무것도 표시되지 않습니다.내 PHP/html 제출 버튼이 눌러지지 않습니다.

<?php 

if($_POST['reg']){ 
/* Make sure values are correct and valid */ 
$getuser = $_POST['user']; 
$getemail = $_POST['email']; 
$getpass = $_POST['password']; 
$getrepass = $_POST['retypepassword']; 

    /* Check to see if username entererd */ 
    if($getuser){ 
     /* Check to see if email entererd */ 
     if($getemail){ 
      /* Check to see if password entererd */ 
      if($getpass){ 
       /* Check to see if retyped password entererd */ 
       if($getrepass){ 
        /* Check to see if passwords are the EXACT same */ 
        if($getpass === $getrepass){ 
         /* Check to see if VALID email is entered */ 
         if((strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))){ 

          /* Email is valid mysql query */ 
          require ("./connect.php"); 

          $query = mysql_query("SELECT * FROM users WHERE username ='$getuser'"); 
          $numrows = mysql_num_rows($query); /* Is mysql returns zero, user doesnot exist. */ 
          /*check if email exists */ 
          if($numrows == 0) { 
           $query = mysql_query("SELECT * FROM users WHERE email ='$getemail'"); 
           $numrows = mysql_num_rows($query); 
           if($numrows == 0){ 
            $date = date("F d, Y"); 
            $code = md5(rand()); 

            mysql_query("INSERT INTO users VALUES ('', '$getuser', '$getpass', '$getemail', '0', '$code', '$date')"); 

            $query = mysql_query ("SELECT ALL * FROM users WHERE username = '$getuser'"); 
            $numrows = mysql_num_rows($query); 
            /* Check to make user was generated */ 
            if($numrows == 1){ 
            $site = "http://www.midnightnachos.com/gs"; 
            $webmaster = "[email protected]"; 
            $headers = "From: $webmaster"; 
            $subject = "Activate Your Account"; 
            $message = "Thanks for registering. Click the link below to activate your account.\n"; 
            $message .= "$site/activate.php?user=$getuser&code=$code\n"; 
            $message .= "You must activate your account to login."; 

            if (mail($getemail, $subject, $message, $headers)){ 
             $errormessage = "You have been registered. You must activate your account from the activation link sent to your email."; 
             echo $form; 
             $getuser = ""; 
             $getpass = ""; 
            } 
            else 
            echo "An error has occured. Your activation email was not sent."; 



            } 
            else 
            $errormessage = "An error has occurred. Account not created."; 


           } 
           else 
           $errormessage = "Email address already in use."; 


          } 
          else 
          $errormessage = "Username already exists."; 



          mysql_close; 
         } 
         else 
         $errormessage = "You did not enter a valid email."; 

        } 
        else 
        $errormessage = "Your passwords did not match."; 


       } 
       else 
       $errormessage = "You must retype your password."; 

      } 

      else 
      $errormessage = "You must enter your password."; 


     } 
     else 
     $errormessage = "You must enter an email to register."; 

    } 
    else 
    $errormessage = "You must enter a username to register."; 

echo $form;   
} 



$form=" <div class='splash'> 
<h1>Register for Game Swap</h1> 
<p>Register for Game Swap to browse what games other local users have added to their library. Propose trades, chat, and meet to swap games. Your email address will only be used to notify you when someone has sent a trade offer. No newsletters, advertisements or updates will be sent by us. We will also never sell your contact information to third parties.</p> 
<br /> 
<p align='center'>Fill out the form below to get started</p> 
<br /> 
<form align='center' action='./register.php' method='POST'> 
    <input type='text' name='user' value='$getuser' class='box' size='30' placeholder='Username' /><br /> 
    <input type='password' name='password' class='box' size='30' placeholder='Password' /><br /> 
    <input type='password' name='retypepassword' class='box' size='30' placeholder='Retype Password' /><br /> 
    <input type='text' name ='email' value='$getemail' class='box' size='30' placeholder='Email Address' /><br /> 
    <input type='button' name='reg' class='loginbutton' value='Register' /><br /> 
    </form> 
    </div> 
    <br/> $errormessage"; 



echo $form; 
?> 


</body> 
</html> 
+2

그 중 일부 * 흥미로운 * 중첩 계속 –

+0

그건 문제를 해결할 수 없지만, 대신 mysql_'의 비표준 기능을 사용하지 마십시오 ... mysqli' 또는'PDO'를 대신 사용하십시오 – Brewal

+2

당신은 내 사용자 이름이 '1'이라면 sql injection을 조사하십시오. DROP TABLE 사용자; - 네 하루 종일 망칠 수있어. – castis

답변

0

내가 그것을 버튼하지만 그래서

제출 아니다 즉 당신이 버튼의 type 속성을 혼합 생각, 난 당신이 일반 텍스트 입력 필드를 추측하지만 CSS는 당신의 눈을 속이는.

<input type="submit" name="reg" value="Register!"/> 

<button name="reg" value="1-or-anything">Register!</button> 

편집 :이

가 사용할 수있는 버튼을 통해 양식을 제출하려면 :)로 작성하십시오

: 및 코딩 (한 번에 모든 유효성 검사 오류를 받고)의 가능한 다른 방법에 관해서는
$error_list = array(); 
if ($condition1) $error_list[] = 'My Error message 1'; 
if ($condition2) $error_list[] = 'My Error message 2'; 
if ($condition3) $error_list[] = 'My Error message 3'; 
... 
if (empty($error_list)) the_fun_part(); 
else { 
    foreach($error_list as $msg) 
     echo "{$msg}<br/>"; 
} 
+0

그건 완전히 고쳐졌습니다. 이 얼마나 작은 감독. 너보다. Filou. 매우 감사! –

관련 문제