Announcement

Collapse
No announcement yet.

Why Reg Page Php 7 MySqli Code Fails While Login Page Code Works ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why Reg Page Php 7 MySqli Code Fails While Login Page Code Works ?

    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','Acc ount_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)


    <?php
    require "header.php";
    ?>
    <!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="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="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="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>
    <div class="form-group">
    <center><label for="remember">Remember Me:</label>
    <input type="checkbox" class="form-control" id="save" name="remember" value="1"></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="index.php">Login here!</a></font></center>
    </form>
    </div>
    </body>
    </html>
    <?php
    require "conn.php";
    if (isset($_POST['submit'])) {
    $username = $_POST["username"];
    $forename = $_POST["forename"];
    $surname = $_POST["surname"];
    $password = $_POST["password"];
    $password_confirmation = $_POST["password_confirmation"];
    $email = $_POST["email"];
    $email_confirmation = $_POST["email_confirmation"];
    if(!$email == $email_confirmation ) {
    echo "<center>Your email inputs do not match! Try inputting again and then re-submit.</center>";
    exit();
    } else {
    }
    if(!$password_confirmation == $password_confirmation) {
    echo "<center>Your password inputs do not match! Try inputting again and then re-submit.</center>";
    exit();
    } else {
    $query = "INSERT INTO users ('Username','Forename','Surname','Email','Password ') VALUES ('$username','$forename','$surname','$email','$pas sword')";
    $result = mysqli_query($conn,$query);
    }
    if($result) {
    echo "<center>Your account has been created! Check your email for the account activation link.</center>";
    } else {
    echo "<center>Something is wrong! Your account has NOT been created! Try again a few minutes later.</center>";
    }
    }


    ?>

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

    LOGIN PAGE (SAMPLE)


    <?php
    session_start();
    require "conn.php";
    if(isset($_POST["member_login_submit"]))
    {
    if(!empty($_POST["member_login_username_or_email"]) && !empty($_POST["member_login_password"]))
    {
    $member_login_username_or_email = mysqli_real_escape_string($conn,$_POST["member_login_username_or_email"]);
    $member_login_password = mysqli_real_escape_string($conn,$_POST["member_login_password"]);
    $sql = "SELECT * FROM users WHERE Username='".$member_login_username_or_email."' OR Email='".$member_login_username_or_email."' AND Password='".$member_login_password."'";
    $result = mysqli_query($conn, $sql);
    $numrows = mysqli_num_rows($result);
    if ($numrows !=0)
    {
    while ($row = mysqli_fetch_assoc($result))
    {
    $id = $row["Id"];
    $db_user_name = $row["Username"];
    $db_password = $row["Password"];
    $db_email = $row["Email"];
    $db_bio = $row["Bio"];
    $db_status = $row["Status"];

    if ($member_login_username_or_email == $db_user_name && $member_login_password == $db_password || $member_login_username_or_email == $db_email && $member_login_password == $db_password)
    {
    $_SESSION["member_username"] = $member_login_username_or_email;
    if(!empty($_POST["member_login_remember"]))
    {
    setcookie("member_login_username_or_email", $member_login_username_or_email, time()+ (10 * 365 * 24 * 60 * 60));
    setcookie("member_login_password", $member_login_password, time()+ (10 * 365 * 24 * 60 * 60));
    }
    else
    {
    if(isset($_COOKIE["member_login_username_or_email"]))
    {
    setcookie("member_login_username_or_email", "", "");
    }
    if(isset($_COOKIE["member_login_password"]))
    {
    setcookie("member_login_password", "", "");
    }
    }
    header("location:home.php");
    }
    else
    {
    $message = "Invalid login!";
    }
    }
    }
    else
    {
    $message = "Something is wrong! Try again later!";
    }
    }
    else
    {
    $message = "You must input your Username and Password!";
    }
    }

    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <title>Login 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">
    <form method="post" action="">
    <center><h3>Member Login Form</h3></center>
    <div class="text-danger">
    <?php
    if(isset($message))
    {
    echo $message;
    }
    ?>
    <div class="form-group">
    <center><label for="member-login-username-or-email">Username/Email:</label>
    <input type="text" class="form-control" placeholder="Enter username or Email" name="member_login_username_or_email" value="<?php if(isset($_COOKIE["member_login_username_or_email"])) echo $_COOKIE["member_login_username_or_email"]; ?>"</center>
    </div>
    <div class="form-group">
    <center><label for="member-login-password">Password:</label>
    <input type="password" class="form-control" placeholder="Enter password" name="member_login_password" value="<?php if(isset($_COOKIE["member_login_password"])) echo $_COOKIE["member_login_password"] ;?>"></center>
    </div>
    <div class="form-group">
    <center><label for="member-login-remember">Remember Login Details:</label>
    <input type="checkbox" name="member_login_remember" /></center>
    </div>
    <div class="form-group">
    <center><input type="submit" name="member_login_submit" value="Login" class="button button-success" /></center>
    </div>
    <div class="form-group">
    <center><font color="red" size="3"><b>Forgot your password ?</b><br><a href="member_login_password_reset.php">Reset it here!</a></font></center>
    <center><font color="red" size="3"><b>Not registered ?</b><br><a href="member_register.php">Register here!</a></font></center>
    </form>
    </div>
    </body>
    </html>
Working...
X