#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    63
    Rep Power
    1

    Question 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)

    PHP Code:
    <!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)

    PHP Code:
    <?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','$password')";
           $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 Code:
    <?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_emailtime()+ (10 365 24 60 60));
                        setcookie("member_login_password"$member_login_passwordtime()+ (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>
  2. #2
  3. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,966
    Rep Power
    9615
    Originally Posted by UniqueIdeaMan
    is not working
    Those words are meaningless.

    What part isn't working? How it is not working? What is it supposed to do and what is it actually doing? And what have you done so far to find and fix the problem by yourself?
  4. #3
  5. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    And please don't forget your [PHP] or [Code] tags next time

    Wrap one or the other around your code and it will make your posts much easier for our members to read.

    Comments on this post

    • requinix agrees
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    63
    Rep Power
    1
    Originally Posted by markroberts
    And please don't forget your [PHP] or [Code] tags next time

    Wrap one or the other around your code and it will make your posts much easier for our members to read.
    Code, I have fixed no but I don't understand what you mean by wrapping. I am new to programming, especially php and so I don't understand technical slangish terminilogy.
    My code does have php tags:

    <? php

    ?>
  8. #5
  9. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    Sorry - I'm not referring to your programming, just to the forums. When you post code on our forums, in a forum post, put [code] before your code and [(slash)code] immediately after your code. Except replace the word (slash) with an actual /

    If your code is PHP, do the same but use [php] instead of [code].

    When you do this, our forums will automatically format your code with the original spacing and everything, and put it into a little box. I'll give you an example below:

    Without code tags on our forums:

    <?php
    fsdjkl sdkfj sl sdjkl
    fj sdklf dkf lsdjklf f lfjsdl k f sjkl
    jfdkl s j jfksdl sdk fl
    jfkl sdkl dfjksl lsdk sdfkl
    ?>

    With code tags on our forums:
    PHP Code:
    <php
    fsdjkl  sdkfj sl sdjkl
    fj sdklf  dkf lsdjklf f lfjsdl k  f sjkl
               jfdkl s j        jfksdl sdk fl
     jfkl               sdkl  dfjksl lsdk          sdfkl
            ?>
     
    These are both written the same way - but the spacing is only revealed in the second example because I used [php] tags.

    It's just a function on our forums that makes it easier for readers to understand your code, and makes it easier for them to help you. It has no application outside of posting code in a forum post on Dev Shed. It's a vbulletin thing.

    Anyway, this is a bit off-topic now. You can email me at markr@imninjas.com if you need more help understanding. Can you answer Requinix's questions?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    63
    Rep Power
    1
    Thank you Mark Roberts for indepth explanation but 5 mins ago reading another member's same explanationsunk into my head that you want me to put my php code within .
    As for answering Mr Requinix, the problem I was facing got solved few days earlier so not delving into the matter anymore.

    Thank you everyone for willing to help and for putting-up with my ignorance.

IMN logo majestic logo threadwatch logo seochat tools logo