0

PHPを追加するまで完全に表示されるメンバー登録フォームがあります。phpコードが追加されると、フォームは完全に消えます。私はすべてを試しましたが、この段階では新鮮な目が必要だと思います。どんな助けでも大歓迎です。乾杯。

<?php

if ( $_POST['registerbtn'] ) {
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getretypepass = $_POST['retypepass'];

    if ($getuser) {
        if ($getemail) {
            if($getpass) {
                if ($getretypepass) {
                    if ($getpass === $getretypepass) {
                        if ( (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))) {
                            require("./connect.php");

                            $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                            $numrows = mysql_num_rows($query);
                            if ($numrows == 0){
                                    $query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
                                    $numrows = mysql_num_rows($query);
                                    if ($numrows == 0){

                                        $password = md5($password);
                                        $date = date("F d, Y");
                                        $code = md5(rand());

                                        mysql_query("INSERT INTO users VALUES (
                                            '', '$getuser', '$getpassword', '$getemail', '0', '$getcode', '$getdate'
                                        )");



                                        $query = mysql_query("SELECT * FROM users WHERE username='$getusername'");
                                        $numrows = mysql_num_rows($query);
                                        if ($numrows == 1) {

                                            $site ="http://localhost/member.php";
                                            $webmaster = "Bror Phren <bmdoublec@hotmail.com>";
                                            $headers = "From: $webmaster";
                                            $subject = "Activate your account";
                                            $message = "Thanks for registering. Click the link below to activate your account";
                                            $message .= "$site/activate.php?user=$getuser&code=$code\n";
                                            $message .= "You must activate your account t login.";

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


                                        }
                                        else
                                            $errormsg = "An error has occured. Your account was not created.\n";


                            }
                            else
                                $errormsg = "There is already a user with that email";

                            }
                            else
                                $errormsg = "There is already a user with that username";

                            mysql_close();


                        }
                        else
                        $errormsg = "You must enter a valid email address to register.";

                }
                else
                $errormsg = "You must retype your password to register.";

            }
            else
            $errormsg = "You must enter password to register.";

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

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

}

$form = "<form action='./register.php' method='post'>
<table>

    <tr>
    <td></td>
    <td><font color='red'>$errormsg</font></td>
    </tr>
    <tr>

    <td>Username:</td>
    <td><input type='text' name='user' value='$getuser' /></td>
    </tr>

    <tr>
    <td>Email:</td>
    <td><input type='text' name='email' value='$getemail' /></td>
    </tr>

    <tr>
    <td>Password:</td>
    <td><input type='password' name='pass' value='' /></td>
    </tr>

        <tr>
    <td>Retype:</td>
    <td><input type='password' name='retypepass' value='' /></td>
    </tr>

        <tr>
    <td>Retype:</td>
    <td><input type='submit' name='registerbtn' value='Register' /></td>
    </tr>

    </table>
</form>";

echo $form;

}

?>
4

4 に答える 4

1

エコーステートメントはif($ _POST ['registerbtn']){}ブロック内にあります。つまり、フォームが送信されない場合、フォームは表示されません。

于 2012-10-26T11:34:24.967 に答える
1

PHPコードにエラーがあり、何も実行できません。

エラーを確認するには、PHPLintなどでコードを実行することをお勧めします。

また、読みやすく、保守しやすい方法でコードを構造化することを検討することもできます。

たとえば、ネストされたifステートメントをすべて回避して、次のように記述することができます。

if (!$getuser) {
   $errormsg = "You must enter username to register.";
}
else if (!$getemail) {
   $errormsg = "You must enter email to register.";
}
...
于 2012-10-26T11:35:20.363 に答える
1

他に使う必要があると思います

<?php

if (isset($_POST['registerbtn'])) {
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getretypepass = $_POST['retypepass'];

    if ($getuser) {
        if ($getemail) {
            if($getpass) {
                if ($getretypepass) {
                    if ($getpass === $getretypepass) {
                        if ( (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))) {
                            require("./connect.php");

                            $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                            $numrows = mysql_num_rows($query);
                            if ($numrows == 0){
                                    $query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
                                    $numrows = mysql_num_rows($query);
                                    if ($numrows == 0){

                                        $password = md5($password);
                                        $date = date("F d, Y");
                                        $code = md5(rand());

                                        mysql_query("INSERT INTO users VALUES (
                                            '', '$getuser', '$getpassword', '$getemail', '0', '$getcode', '$getdate'
                                        )");



                                        $query = mysql_query("SELECT * FROM users WHERE username='$getusername'");
                                        $numrows = mysql_num_rows($query);
                                        if ($numrows == 1) {

                                            $site ="http://localhost/member.php";
                                            $webmaster = "Bror Phren <bmdoublec@hotmail.com>";
                                            $headers = "From: $webmaster";
                                            $subject = "Activate your account";
                                            $message = "Thanks for registering. Click the link below to activate your account";
                                            $message .= "$site/activate.php?user=$getuser&code=$code\n";
                                            $message .= "You must activate your account t login.";

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


                                        }
                                        else
                                            $errormsg = "An error has occured. Your account was not created.\n";


                            }
                            else
                                $errormsg = "There is already a user with that email";

                            }
                            else
                                $errormsg = "There is already a user with that username";

                            mysql_close();


                        }
                        else
                        $errormsg = "You must enter a valid email address to register.";

                }
                else
                $errormsg = "You must retype your password to register.";

            }
            else
              $errormsg = "You must enter password to register.";

        }
        else
            $errormsg = "You must enter email to register.";
    }
    else
        $errormsg = "You must enter username to register.";
}
}

ここ

else{ 
$form = "<form action='./register.php' method='post'>
<table>

    <tr>
    <td></td>
    <td><font color='red'>$errormsg</font></td>
    </tr>
    <tr>

    <td>Username:</td>
    <td><input type='text' name='user' value='$getuser' /></td>
    </tr>

    <tr>
    <td>Email:</td>
    <td><input type='text' name='email' value='$getemail' /></td>
    </tr>

    <tr>
    <td>Password:</td>
    <td><input type='password' name='pass' value='' /></td>
    </tr>

        <tr>
    <td>Retype:</td>
    <td><input type='password' name='retypepass' value='' /></td>
    </tr>

        <tr>
    <td>Retype:</td>
    <td><input type='submit' name='registerbtn' value='Register' /></td>
    </tr>

    </table>
</form>";

echo $form;

}

?>
于 2012-10-26T11:42:30.550 に答える
0

編集:Armon Toubmanが述べたように、フォームは関連データがページに投稿されている場合にのみ表示されます。フォームをifステートメントの外に移動する必要があります。以下のコードを参照してください。

<?php

if ( $_POST['registerbtn'] ) {
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getretypepass = $_POST['retypepass'];

    if ($getuser) {
        if ($getemail) {
            if($getpass) {
                if ($getretypepass) {
                    if ($getpass === $getretypepass) {
                        if ( (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))) {
                            require("./connect.php");

                            $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                            $numrows = mysql_num_rows($query);
                            if ($numrows == 0){
                                    $query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
                                    $numrows = mysql_num_rows($query);
                                    if ($numrows == 0){

                                        $password = md5($password);
                                        $date = date("F d, Y");
                                        $code = md5(rand());

                                        mysql_query("INSERT INTO users VALUES (
                                            '', '$getuser', '$getpassword', '$getemail', '0', '$getcode', '$getdate'
                                        )");



                                        $query = mysql_query("SELECT * FROM users WHERE username='$getusername'");
                                        $numrows = mysql_num_rows($query);
                                        if ($numrows == 1) {

                                            $site ="http://localhost/member.php";
                                            $webmaster = "Bror Phren <bmdoublec@hotmail.com>";
                                            $headers = "From: $webmaster";
                                            $subject = "Activate your account";
                                            $message = "Thanks for registering. Click the link below to activate your account";
                                            $message .= "$site/activate.php?user=$getuser&code=$code\n";
                                            $message .= "You must activate your account t login.";

                                            if (mail($getemail, $subject, $message, $headers) ) {
                                                $errormsg = "You have been registered. You must activate your account from the activation link sent to <b>$getemail</b> ";
                                                $getuser = "";
                                                $getemail = "";
                                            }
                                            else
                                                $errormsg = "An error has occured. Your activation email was not sent";
                                        }
                                        else
                                            $errormsg = "An error has occured. Your account was not created.\n";
                            }
                            else
                                $errormsg = "There is already a user with that email";
                            }
                            else
                                $errormsg = "There is already a user with that username";
                        }
                        else
                        $errormsg = "You must enter a valid email address to register.";
                }
                else
                $errormsg = "You must retype your password to register.";
            }
            else
            $errormsg = "You must enter password to register.";
        }
        else
            $errormsg = "You must enter email to register.";

    }
    else
        $errormsg = "You must enter username to register.";
    }
    mysql_close();
}
?>
<form action='./register.php' method='post'>
<table>

    <tr>
      <td></td>
      <td><font color='red'><?php if(isset($errormsg){ echo $errormsg; } ?></font></td>
    </tr>

    <tr>    
      <td>Username:</td>
      <td><input type='text' name='user' value='<?php if(isset($getuser){ echo $getuser; } ?>' /></td>
    </tr>

    <tr>
      <td>Email:</td>
      <td><input type='text' name='email' value='<?php if(isset($getemail){ echo $getemail; } ?>' /></td>
    </tr>

    <tr>
      <td>Password:</td>
      <td><input type='password' name='pass' value='' /></td>
    </tr>

    <tr>
      <td>Retype:</td>
      <td><input type='password' name='retypepass' value='' /></td>
    </tr>

    <tr>
      <td>Retype:</td>
      <td><input type='submit' name='registerbtn' value='Register' /></td>
    </tr>

    </table>
</form>
于 2012-10-26T11:32:01.180 に答える