我正在使用HTML和PHP编写登录页面

问题描述 投票:-3回答:1

when I press sign up (without filling any fields

when I run my code

如果有人有兴趣帮助我,以下是所有代码:

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>Etego</title>
</head>    
<body>
<div align="center">
    <h3>Sign Up</h3>
    <br />    <br />    <br />
    <form method="post" action="">
        <table>
        <tr>
            <td align="right" > <label for="username">Username</label> </td>
            <td  > <input type="text"  placeholder="Username" id="username" name="username"  /> </td>
       </tr>
         <!--  ------------------------------------------------------------------------------------------------------- -->
        <tr>
            <td align="right"  > <label for="email">Email</label> </td>
            <td  > <input type="email"  placeholder="email" id="email" name="email" /> </td>
       </tr>

            <!-- ------------------------------------------------------------------------------------------------------- -->
        <tr>
            <td align="right" > <label for="email2">Confirm Email</label> </td>
            <td > <input type="email"  placeholder="re-enter email" id="email2" name="email2" /> </td>
       </tr>
       <!-- ------------------------------------------------------------------------------------------------------ -->
        <tr>
            <td align="right" > <label for="password">Password</label> </td>
            <td > <input type="password"  placeholder="password" id="password" name="password" /> </td>
       </tr>
        <!--------------------------------------------------------------------------------------------------------- -->
        <tr>
            <td align="right" > <label for="password2">Confirm Password</label> </td>
            <td > <input type="password"  placeholder="re-enter Password" id="password2" name="password2" /> </td>
       </tr>
       <!-- ------------------------------------------------------------------------------------------------------- -->
        <tr>
            <td>    
                <p>
                    <td>

What is your Gender?

<select name="formGender">
  <option value="NS">non specified</option>
  <option value="M">Male</option>
  <option value="F">Female</option>
</select>
        </td>

        <td > <input type="hidden"  placeholder="" id="gender" name="gender" /> </td>
</p>
</td>  
       </tr>
                      <!-- ------------------------------------------------------------------------------------------------------- -->
            <tr>
            <td></td>
            <td>
                <br />
               <input type="submit" name="signup" value="Sign Up">
               <input type="hidden" name="sign" value="true">
            </td>
                </tr>
        </table>
    </form>
</div>
</body>
</html>
<?php
    $bdd = new PDO ('mysql:host=127.0.0.1;dbname=members', 'root' , '');
    $gender = htmlspecialchars($_POST['gender']);
    $username = htmlspecialchars($_POST['username']);
    $email = htmlspecialchars($_POST['email']);
    $email2 = htmlspecialchars($_POST['email2']);
    $password = sha1($_POST['password']);
    $password2 = sha1($_POST['password2']);
    $reqemail = $bdd->prepare("SELECT * FROM members WHERE email = ?");
    $reqemail->execute(array($email));
    $emailexist = $reqemail->rowCount();
    if($emailexist == 0) {
        $passwordlenght = strlen($password);
        if($passwordlenght >= 4) {
            $usernamelenght = strlen($username);
            if($usernamelenght <= 25) {
            if($email == $email2) {
                if($password == $password2) {
                    if (filter_var($email, FILTER_VALIDATE_EMAIL )) {
                        $insertmbr = $bdd->prepare("INSERT INTO members(username, email, password, gender) VALUES(?, ?, ?, ?)");
                        $insertmbr->execute(array($username, $email, $password, $gender));
                        echo "<p> <font color=red font face='arial' size='3pt'>Your account has been created</font> </p>";
                        header('location:login.php');
                    } else {
                        echo "<p> <font color=red font face='arial' size='3pt'>Your email isnt valid!</font> </p>";
                    }
                } else {    
                    echo "<p> <font color=red font face='arial' size='3pt'>Your confirmation password doesnt match with your password</font> </p>";
                }
            } else {    
                echo "<p> <font color=red font face='arial' size='3pt'>Your confirmation email doesnt match with your email</font> </p>";
            }    
        } else { 
            echo "<p> <font color=red font face='arial' size='3pt'>Your username may not exceed 25 characters</font> </p>";
        }
    } else {
        echo "<p> <font color=red font face='arial' size='3pt'>Your password must be 5 characters or more</font> </p>";
    }
} else {
    echo "<p> <font color=red font face='arial' size='3pt'>Your email is already being used by a user</font> </p>";
}
//---------------------------------------------EMPTY FIELDS ERROR-----------------------------------------------------------------------------------------
if (!empty($_POST['sign']) && $_POST['sign']=="true") 
    if($_POST['sign']=="true") {
        if(empty($_POST['username'])) { 
            echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill username</font> </p>"; 
        } else { 
            $username = $_POST['username']; 
        } 
        if(empty($_POST['email'])) { 
            echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill email</font> </p>"; 
        } else { 
            $email = $_POST['email']; 
        } 
        if(empty($_POST['email2'])) { 
            echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill confirmation email</font> </p>"; 
        } else { 
            $email2 = $_POST['email2'];
        } 
        if(empty($_POST['password'])) { 
            echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill password</font> </p>"; 
        } else { 
            $password = $_POST['password']; 
        } 
        if(empty($_POST['password2'])) { 
            echo "<p> <font color=red font face='arial' size='3pt'>please go back and fill confirmation password</font> </p>"; 
        } else { 
            $password2 = $_POST['password2']; 
        } 
    } 
?>

我使用phpmyadmin和“成员”是我的浏览,它有id,用户名,密码,电子邮件,我最近添加了性别的东西。

php html
1个回答
-2
投票

嗨查尔斯你的代码非常混乱,但有一些功能,我可以学习一点,也许下次修复你的代码。它也是为了你自己的利益。我修复你的代码,但你要使用两个php一个用于signup.php,第二个是login.php < - signup.php - >

<html>
<head>
<meta charset="utf-8">
<title>Etego</title>
</head>    
<body>
<div align="center">
<h3>Sign Up</h3>
<br /><br /><br />
<form method="POST" action="login.php">
<table>
    <tr>
    <td align="right" > <label for="username">Username</label> </td>
    <td  > <input type="text"  placeholder="Username" id="username" name="username"  /> </td>
    </tr>
    <tr>
    <td align="right"  > <label for="email">Email</label> </td>
    <td><input type="email"  placeholder="email" id="email" name="email" /> </td>
    </tr>
    <tr>
     <td align="right" > <label for="email2">Confirm Email</label> </td>
     <td > <input type="email"  placeholder="re-enter email" id="email2" name="email2" />      </td>
    </tr>
    <tr>
    <td align="right" > <label for="password">Password</label> </td>
    <td > <input type="password"  placeholder="password" id="password" name="password" /> </td>
    </tr>
    <tr>
    <td align="right" > <label for="password2">Confirm Password</label> </td>
    <td > <input type="password"  placeholder="re-enter Password" id="password2" 
  name="password2" /> </td>
    </tr>
     <tr>
  <td>    
<p>
<td>
What is your Gender?
<select name="gender">
<option value="NS">non specified</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
    </td>
    <td><input type="hidden"  placeholder="" id="gender" name="gender" /> </td>
</p>
 </td>  
 </tr>
 <tr>      
 <td></td>
 <td>
 <br />
 <input type="submit" name="signup" value="Sign Up">
 <input type="hidden" name="sign" value="true">
 </td>
 </tr>
 </table>
 </form>
 </div>
 </body>
 </html>

//login.PHP

  <?php
  $bdd = new PDO ('mysql:host=localhost;dbname=dbname', 'root' , '');//make sure your 
  database name was really a members
  $gender = htmlspecialchars($_POST["gender"]);
  $username = htmlspecialchars($_POST['username']);
  $email = htmlspecialchars($_POST['email']);
  $email2 = htmlspecialchars($_POST['email2']);
  $password = sha1($_POST['password']);
  $password2 = sha1($_POST['password2']);
  $reqemail = $bdd->prepare("SELECT * FROM members");
  $reqemail->execute(array($email));
  $emailexist = $reqemail->rowCount();
  if($emailexist == 0) 
  {
  $passwordlenght = strlen($password);
  if($passwordlenght >= 4)
  {
  $usernamelenght = strlen($username);
  if($usernamelenght <= 25)
  {
  if($email == $email2)
   {
   if($password == $password2)
   {
    if (filter_var($email, FILTER_VALIDATE_EMAIL ))
  {
   $insertmbr = $bdd->prepare("INSERT INTO members(username, email, password, gender) 
   VALUES(?,?,?,?)");
   $insertmbr->execute(array($username, $email, $password, $gender));
    echo "<p> <font color=green font face='arial' size='3pt'>Your account has been created</font> </p>";
    header('location:');
   }
   else
   {
    echo "<p> <font color=red font face='arial' size='3pt'>Your email isnt valid! 
   </font> </p>";
    }
    }
   else
    {    
      echo "<p> <font color=red font face='arial' size='3pt'>Your confirmation 
          password doesnt match with your password</font> </p>";

    }
   }
    else
    {    
     echo "<p> <font color=red font face='arial' size='3pt'>Your confirmation email 
     doesnt match with your email</font> </p>";
     }
    }
     else
     { 
      echo "<p> <font color=red font face='arial' size='3pt'>Your username may not 
      exceed 25 characters</font> </p>";
      }
     }
    else
    {
    echo "<p> <font color=red font face='arial' size='3pt'>Your password must be 5 
    characters or more</font> </p>";
    }
    }
    else
    {
    echo "<p> <font color=red font face='arial' size='3pt'>Your email is already 
    being used by a user</font> </p>";
    }
     if (!empty($_POST['sign']) && $_POST['sign']=="true") 
     if($_POST['sign']=="true") {
     if(empty($_POST['username']))
         { echo "<p> <font color=red font face='arial' size='3pt'>please go back and 
       fill username</font> </p>"; }
     else { $username = $_POST['username'];} 
     if(empty($_POST['email']))
        { echo "<p> <font color=red font face='arial' size='3pt'>please go back and 
       fill email</font> </p>"; }
      else { $email = $_POST['email']; } 
       if(empty($_POST['email2']))
        { echo "<p> <font color=red font face='arial' size='3pt'>please go back and 
        fill confirmation email</font> </p>"; }
      else { $email2 = $_POST['email2']; } 
      if(empty($_POST['password']))
        { echo "<p> <font color=red font face='arial' size='3pt'>please go back and 
      fill password</font> </p>"; }
      else { $password = $_POST['password']; } 
      if(empty($_POST['password2']))
        { echo "<p> <font color=red font face='arial' size='3pt'>please go back and 
       fill confirmation password</font> </p>"; }
       else { $password2 = $_POST['password2']; } 
       } 
       ?>
© www.soinside.com 2019 - 2024. All rights reserved.