Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Why Reg Page Php 7 MySqli Code Fails While Login Page Code Works ?

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 523
    Answer it

    Hi,

    I am using php 7 and I do not know why the following 2 different codes for user the user registration page is not working. The login page php is working, though. I would appreciate the communities feed-backs.

    Thank You!

     

    REG PAGE (SAMPLE 1)

    <!DOCTYPE html>
    <html>
    <head>
    <title>Signup Page</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
    <div class = "container">
    <center><h2>Signup Form</h2></center>
    <form method="post" action="">
    <div class="form-group">
    <center><label for="username">Username:</label>
    <input type="text" class="form-control" id="user" placeholder="Enter a unique username" name="username"></center>
    </div>
    <div class="form-group">
    <center><label for="password">Password:</label>
    <input type="password" class="form-control" id="pwd" placeholder="Enter new password" name="password"></center>
    </div>
    <div class="form-group">
    <center><label for="password">Repeat Password:</label>
    <input type="password" class="form-control" id="repeat_pwd" placeholder="Repeat new password" name="password_confirmation"></center>
    </div>
    <div class="form-group">
    <center><label for="forename">First Name:</label>
    <input type="text" class="form-control" id="first_name" placeholder="Enter your First Name" name="forename"></center>
    </div>
    <div class="form-group">
    <center><label for="surname">Surname:</label>
    <input type="text" class="form-control" id="last_name" placeholder="Enter your Surname" name="surname"></center>
    </div>
    <div class="form-group">
    <center><label for="email">Email:</label>
    <input type="email" class="form-control" id="email" placeholder="Enter your email" name="email"></center>
    </div>
    <div class="form-group">
    <center><label for="email">Repeat Email:</label>
    <input type="email" class="form-control" id="repeat_email" placeholder="Repeat your email" name="email_confirmation"></center>
    </div>
    <center><button type="submit" class="btn btn-default" name="submit">Register!</button></center>
    <center><font color="red" size="3"><b>Already have an account ?</b><br><a href="login.php">Login here!</a></font></center>
    </form>
    </div>
    </body>
    </html>
    <?php
    require "conn.php";
    if  (isset($_POST['submit'])) {
        $username = mysqli_real_escape_string($conn,$_POST["username"]);
        $forename = mysqli_real_escape_string($conn,$_POST["forename"]);
        $surname = mysqli_real_escape_string($conn,$_POST["surname"]);
        $password = mysqli_real_escape_string($conn,$_POST["password"]);
        $password_confirmation = mysqli_real_escape_string($conn,$_POST["password_confirmation"]);
        $email = mysqli_real_escape_string($conn,$_POST["email"]);
        $email_confirmation = mysqli_real_escape_string($conn,$_POST["email_confirmation"]);
        $account_activation_code = mysqli_real_escape_string(md5($conn,$_POST["username"] + microtime()));
        $account_activation = 0;
        if(!$email == $email_confirmation ) {
        echo "<center>Your email inputs do not match! Try inputting again and then re-submit.</center>";
        exit();
        $conn->close();
        } 
        else
        {    
        }
        if(!$password_confirmation == $password_confirmation) {
        echo "<center>Your password inputs do not match! Try inputting again and then re-submit.</center>";
        exit();
        $conn->close();
        }
        else
        {
        }        
        $query_1 = "INSERT INTO pending_users ('Username','Password','Forename','Surname','Email') VALUES ('$username','$password','$forename','$surname','$email')";
        $mysqli->query($query_1);
        $result_1 = mysqli>query($conn, $query_1);
        if($result_1) {
        echo "Done!";
        }
        else
        {    
        echo "<center>Something is wrong! Result 1 fail.</center>";
        exit();
        $conn->close();
        }       
        $query_2 = "INSERT INTO account_activation ('Username','Email','Account_Activation_Code','Account_Activation') VALUES ('$username','$email','$account_activation_code','$account_activation')";
        $result_2 = mysqli>query($conn, $query_2);      
           if($result_2) {
           echo "Done!";
           }
           else
           {    
            echo "Result 2 fail.</center>";
            $conn->close();
           } 
    }
    
    
    ?>


    ------------

    REG PAGE (SAMPLE 2)

    <!DOCTYPE html>
    <html>
    <head>
    <title>Signup Page</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
    <div class = "container">
    <center><h2>Signup Form</h2></center>
    <form method="post" action="">
    <div class="form-group">
    <center><label for="username">Username:</label>
    <input type="text" class="form-control" id="user" placeholder="Enter a unique username" name="username"></center>
    </div>
    <div class="form-group">
    <center><label for="password">Password:</label>
    <input type="password" class="form-control" id="pwd" placeholder="Enter new password" name="password"></center>
    </div>
    <div class="form-group">
    <center><label for="password">Repeat Password:</label>
    <input type="password" class="form-control" id="repeat_pwd" placeholder="Repeat new password" name="password_confirmation"></center>
    </div>
    <div class="form-group">
    <center><label for="forename">First Name:</label>
    <input type="text" class="form-control" id="first_name" placeholder="Enter your First Name" name="forename"></center>
    </div>
    <div class="form-group">
    <center><label for="surname">Surname:</label>
    <input type="text" class="form-control" id="last_name" placeholder="Enter your Surname" name="surname"></center>
    </div>
    <div class="form-group">
    <center><label for="email">Email:</label>
    <input type="email" class="form-control" id="email" placeholder="Enter your email" name="email"></center>
    </div>
    <div class="form-group">
    <center><label for="email">Repeat Email:</label>
    <input type="email" class="form-control" id="repeat_email" placeholder="Repeat your email" name="email_confirmation"></center>
    </div>
    <center><button type="submit" class="btn btn-default" name="submit">Register!</button></center>
    <center><font color="red" size="3"><b>Already have an account ?</b><br><a href="login.php">Login here!</a></font></center>
    </form>
    </div>
    </body>
    </html>
    <?php
    require "conn.php";
    if  (isset($_POST['submit'])) {
        $username = mysqli_real_escape_string($conn,$_POST["username"]);
        $forename = mysqli_real_escape_string($conn,$_POST["forename"]);
        $surname = mysqli_real_escape_string($conn,$_POST["surname"]);
        $password = mysqli_real_escape_string($conn,$_POST["password"]);
        $password_confirmation = mysqli_real_escape_string($conn,$_POST["password_confirmation"]);
        $email = mysqli_real_escape_string($conn,$_POST["email"]);
        $email_confirmation = mysqli_real_escape_string($conn,$_POST["email_confirmation"]);
        $account_activation_code = mysqli_real_escape_string(md5($conn,$_POST["username"] + microtime()));
        $account_activation = 0;
        if(!$email == $email_confirmation ) {
        echo "<center>Your email inputs do not match! Try inputting again and then re-submit.</center>";
        exit();
        $conn->close();
        } 
        else
        {    
        }
        if(!$password_confirmation == $password_confirmation) {
        echo "<center>Your password inputs do not match! Try inputting again and then re-submit.</center>";
        exit();
        $conn->close();
        }
        else
        {
        }        
        $query_1 = "INSERT INTO pending_users ('Username','Password','Forename','Surname','Email') VALUES ('$username','$password','$forename','$surname','$email')";
        $mysqli->query($query_1);
        $result_1 = mysqli>query($conn, $query_1);
        if($result_1) {
        echo "Done!";
        }
        else
        {    
        echo "<center>Something is wrong! Result 1 fail.</center>";
        exit();
        $conn->close();
        }       
        $query_2 = "INSERT INTO account_activation ('Username','Email','Account_Activation_Code','Account_Activation') VALUES ('$username','$email','$account_activation_code','$account_activation')";
        $result_2 = mysqli>query($conn, $query_2);      
           if($result_2) {
           echo "Done!";
           }
           else
           {    
            echo "Result 2 fail.</center>";
            $conn->close();
           } 
    }
    
    
    ?>

    ----------------

    LOGIN PAGE (SAMPLE)

    <!DOCTYPE html>
    <html>
    <head>
    <title>Signup Page</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
    <div class = "container">
    <center><h2>Signup Form</h2></center>
    <form method="post" action="">
    <div class="form-group">
    <center><label for="username">Username:</label>
    <input type="text" class="form-control" id="user" placeholder="Enter a unique username" name="username"></center>
    </div>
    <div class="form-group">
    <center><label for="password">Password:</label>
    <input type="password" class="form-control" id="pwd" placeholder="Enter new password" name="password"></center>
    </div>
    <div class="form-group">
    <center><label for="password">Repeat Password:</label>
    <input type="password" class="form-control" id="repeat_pwd" placeholder="Repeat new password" name="password_confirmation"></center>
    </div>
    <div class="form-group">
    <center><label for="forename">First Name:</label>
    <input type="text" class="form-control" id="first_name" placeholder="Enter your First Name" name="forename"></center>
    </div>
    <div class="form-group">
    <center><label for="surname">Surname:</label>
    <input type="text" class="form-control" id="last_name" placeholder="Enter your Surname" name="surname"></center>
    </div>
    <div class="form-group">
    <center><label for="email">Email:</label>
    <input type="email" class="form-control" id="email" placeholder="Enter your email" name="email"></center>
    </div>
    <div class="form-group">
    <center><label for="email">Repeat Email:</label>
    <input type="email" class="form-control" id="repeat_email" placeholder="Repeat your email" name="email_confirmation"></center>
    </div>
    <center><button type="submit" class="btn btn-default" name="submit">Register!</button></center>
    <center><font color="red" size="3"><b>Already have an account ?</b><br><a href="login.php">Login here!</a></font></center>
    </form>
    </div>
    </body>
    </html>
    <?php
    require "conn.php";
    if  (isset($_POST['submit'])) {
        $username = mysqli_real_escape_string($conn,$_POST["username"]);
        $forename = mysqli_real_escape_string($conn,$_POST["forename"]);
        $surname = mysqli_real_escape_string($conn,$_POST["surname"]);
        $password = mysqli_real_escape_string($conn,$_POST["password"]);
        $password_confirmation = mysqli_real_escape_string($conn,$_POST["password_confirmation"]);
        $email = mysqli_real_escape_string($conn,$_POST["email"]);
        $email_confirmation = mysqli_real_escape_string($conn,$_POST["email_confirmation"]);
        $account_activation_code = mysqli_real_escape_string(md5($conn,$_POST["username"] + microtime()));
        $account_activation = 0;
        if(!$email == $email_confirmation ) {
        echo "<center>Your email inputs do not match! Try inputting again and then re-submit.</center>";
        exit();
        $conn->close();
        } 
        else
        {    
        }
        if(!$password_confirmation == $password_confirmation) {
        echo "<center>Your password inputs do not match! Try inputting again and then re-submit.</center>";
        exit();
        $conn->close();
        }
        else
        {
        }        
        $query_1 = "INSERT INTO pending_users ('Username','Password','Forename','Surname','Email') VALUES ('$username','$password','$forename','$surname','$email')";
        $mysqli->query($query_1);
        $result_1 = mysqli>query($conn, $query_1);
        if($result_1) {
        echo "Done!";
        }
        else
        {    
        echo "<center>Something is wrong! Result 1 fail.</center>";
        exit();
        $conn->close();
        }       
        $query_2 = "INSERT INTO account_activation ('Username','Email','Account_Activation_Code','Account_Activation') VALUES ('$username','$email','$account_activation_code','$account_activation')";
        $result_2 = mysqli>query($conn, $query_2);      
           if($result_2) {
           echo "Done!";
           }
           else
           {    
            echo "Result 2 fail.</center>";
            $conn->close();
           } 
    }
    
    
    ?>

     

 1 Answer(s)

  • I just checked your mentioned codes for login. You are showing same code in different samples. Why did you do this? I want to suggest to use php code above the html part. Some functions of php can throw warning because of this. You need to remove below mentioned line from your code.
     
    $mysqli->query($query_1);
    
    Thank you
    Deepak Verma
    
    
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: