PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Tue Dec 12, 2017 9:15 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Nov 26, 2017 12:12 pm 
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 178
Php Gurus,

I built a registration.php but I know not why I see a blank page after clicking "Register" button.
Ignore the <center> tag for the time being. Will replace that with <p align> tag. I put echoes on conditions to see which part of the conditions get triggered. But the echoes don't occur.

And, out of the following 2, which one suits my context ?

Syntax: [ Download ] [ Hide ]
$row = mysqli_fetch_array($result, MYSQLI_ASSOC); // Use this line or next ?
$row = mysqli_stmt_fetch($stmt); //Use this line or previous ? 


Syntax: [ Download ] [ Hide ]


    ini_set('display_errors', '1');
    ini_set('display_startup_errors', '1');

    include 'config.php';

    //Step 1: Before registering User account, check if User is already 
    registered or not.

    //Check if User is already logged-in or not.
    if (is_logged() === true) {
        die("You are already logged-in! No need to register again!");

    //Step 2: Check User Submitted Details.
        //Check if user made all the required inputs or not.
        if (isset($_POST["username"]) && 
           isset($_POST["password"]) &&
           isset($_POST["password_confirmation"]) && 
           isset($_POST["email"]) && 
           isset($_POST["email_confirmation"]) && 
           isset($_POST["first_name"]) && 
           isset($_POST["surname"]) && 
           isset($_POST["gender"])) {
    //Step  3: Check User details for matches against database. If no matches 
    then validate inputs and register User account.
            //Create variables based on user inputs.
            $username     = trim($_POST["username"]);
            $password     = $_POST["password"];
            $password_confirmation = $_POST["password_confirmation"];
            $email         = trim($_POST["email"]);
            $email_confirmation = trim($_POST["email_confirmation"]);
            $first_name    = trim($_POST["first_name"]);
            $surname     = trim($_POST["surname"]);
            $gender     = $_POST["gender"];    
               $account_activation_code = sha1( (string) mt_rand(5, 30)); //Type 
    Casted the INT to STRING on the 1st parameter of sha1 as it needs to be a 
            $account_activation_link = 
            $account_activation_status = 0; // 1 = active; 0 = not active.
            $hashed_password = password_hash($password, PASSWORD_DEFAULT); 
    //Encrypt the password.
            //Select Username and Email to check against Mysql DB if they are 
    already registered or not.
            $stmt = mysqli_prepare($conn, "SELECT usernames, emails FROM users 
    WHERE usernames = ? OR emails = ?"
            mysqli_stmt_bind_param($stmt, 'ss', $username, $email);
            $result = mysqli_stmt_bind_result($stmt, $db_username, $db_email);    
            //$row = mysqli_fetch_array($result, MYSQLI_ASSOC); // Use this line 
    or next ?
            $row = mysqli_stmt_fetch($stmt); //Use this line or previous ?    
            // Check if inputted Username is already registered or not.
            if ($row['usernames'] == $username) {
                $_SESSION['error'] = "That username is already registered.";
            // Check if inputted Username is between the required 8 to 30 
    characters long or not.
            } elseif (strlen($username) < 8 || strlen($username) > 30) {
                $_SESSION['error'] = "Username must be between 8 to 30 
    characters long!"
            // Check if both inputted Emails match or not.
            } elseif ($email != $email_confirmation) {
                $_SESSION['error'] = "Emails don't match!";
            // Check if inputed Email is valid or not.
            } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                $_SESSION['error'] = "Invalid email! Insert your real Email in 
    order for us to email you your account activation details."
            // Check if inputted Email is already registered or not.
            } elseif ($row['emails'] == $email) {
                $_SESSION['error'] = "That email is already registered.";
            // Check if both inputted Passwords match or not.
            } elseif ($password != $password_confirmation) {
                $_SESSION['error'] = "Passwords don't match.";
            // Check if Password is between 8 to 30 characters long or not.
            } elseif (strlen($password) < 8 || strlen($password) > 30) {
                $_SESSION['error'] = "Password must be between 6 to 30 
    characters long!"
                echo "line 88";
                //Insert the user's inputs into Mysql database using php's sql 
    injection prevention method "Prepared Statements".
                $stmt = mysqli_prepare($conn, "INSERT INTO users(usernames, 
    passwords, emails, first_names, surnames, genders, 
    accounts_activations_codes, accounts_activations_statuses) VALUES (?, ?, ?, 
    ?, ?, ?, ?, ?)"
                mysqli_stmt_bind_param($stmt, 'sssssssi', $username, 
    $hashed_password, $email, $first_name, $surname, $gender, 
    $account_activation_code, $account_activation_status);
                echo "line 96";
                //Check if user's registration data was successfully submitted 
    or not.
                if (!$stmt)
                    $_SESSION['error'] = "Sorry! Our system is currently 
    experiencing a problem registering your account! You may try registering 
    some other time."
                    echo "line 102";
                    echo "line 107";
                    //Email the account activation link for user to click it to 
    confirm their email and activate their new account.
                    $to = $email;
                    $subject = "Your ".$site_name." account activation 
                    $body  = nl2br("
.$site_name." \r\n
                    From: "
                    To: "
                    Subject: Yours "
.$subject." \r\n
                    Message: "
.$first_name." ".$surname."\r\n You need to click 
    on this following <a href="
.$account_activation_link.">link</a> to activate 
    your account. \r\n"
                    $headers = "From: " . $site_admin_email . "\r\n";
                    if (!mail($to,$subject,$body,$headers)) 
                        $_SESSION['error'] = "Sorry! We have failed to email you 
    your account activation details. Please contact the website administrator!"
                        echo "<h3 style='text-align:center'>Thank you for your 
    registration!<br /> Check your email for details on how to activate your 
    account which you just registered.</h3>"


    <!DOCTYPE html>
            <title><?php $social_network_name ?> Signup Page</title>
    <div class ="container">

    // Error Messages.
    if (isset($_SESSION['error']) && !empty($_SESSION['error'])) {
        echo '<p style="color:red;">'.$_SESSION['error'].'</p>';

    //Session Messages.
    if (isset($_SESSION['message']) && !empty($_SESSION['message'])) {
        echo '<p style="color:red;">'.$_SESSION['error'].'</p>';

    //Clear Registration Session.
    function clear_registration_session()
            //Clear the User Form inputs, Session Messages and Session Errors so 
    they can no longer be used.

    <form method="post" action="">
        <center><h2>Signup Form</h2></center>
        <div class="form-group">
            <input type="text" placeholder="Enter a unique Username" 
    name="username" required [A-Za-z0-9] value="<?php 
    if(isset($_POST['username'])) { echo htmlentities($_POST['username']); }?>">
        <div class="form-group">
            <input type="password" placeholder="Enter a new Password" 
    name="password" required [A-Za-z0-9]></center>
        <div class="form-group">
            <center><label>Repeat Password:</label>
            <input type="password" placeholder="Repeat a new Password" 
    name="password_confirmation" required [A-Za-z0-9]></center>
            <div class="form-group">
            <input type="email" placeholder="Enter your Email" name="email" 
    required [A-Za-z0-9] value="<?php if(isset($_POST['email'])) { echo 
    htmlentities($_POST['email']); }?>"></center>
        <div class="form-group">
            <center><label>Repeat Email:</label>
            <input type="email" placeholder="Repeat your Email" 
    name="email_confirmation" required [A-Za-z0-9] value="<?php 
    if(isset($_POST['email_confirmation'])) { echo 
    htmlentities($_POST['email_confirmation']); }?>"></center>
        <div class="form-group">
            <center><label>First Name:</label>
            <input type="text" placeholder="Enter your First Name" 
    name="first_name" required [A-Za-z] value="<?php 
    if(isset($_POST['first_name'])) { echo htmlentities($_POST['first_name']); 
        <div class="form-group">
            <input type="text" placeholder="Enter your Surname" name="surname" 
    required [A-Za-z] value="<?php if(isset($_POST['surname'])) { echo 
    htmlentities($_POST['surname']); }?>"></center>
        <div class="form-group">
            <input type="radio" name="gender" value="male" <?php 
    if(isset($_POST['gender'])) { echo 'checked'; }?> required>Male<input 
    type="radio" name="gender" value="female" <?php if(isset($_POST['gender'])) 
    { echo 'checked'; }?> required>Female</center>
        <center><button type="submit" class="btn btn-default" 
        <center><font color="red" size="3"><b>Already have an account ?</b><br>
    <a href="login.php">Login here!</a></font></center>

Last edited by requinix on Sun Nov 26, 2017 12:42 pm, edited 1 time in total.
[php] -> [syntax=php]

PostPosted: Sun Nov 26, 2017 1:09 pm 
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13457
Location: New York, NY, US
UniqueIdeaMan wrote:
I put echoes on conditions to see which part of the conditions get triggered. But the echoes don't occur.
That means none of the conditions in which you put echo() were not met.


PostPosted: Sun Nov 26, 2017 10:15 pm 
Forum Newbie

Joined: Sun Nov 15, 2015 12:57 pm
Posts: 11
When you have an error you set a session but then kill the script, thus the blank page.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: Bing [Bot] and 21 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group