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

    Join Date
    Jan 2017
    Posts
    307
    Rep Power
    1

    Which Suits My Purpose get_result Or bind_result ?


    Php Folks,

    You will notice that, I have a question on my comments where I show confusion on how to proceed forward. I ask which 1 of the following 2 I should use which will suit the context of my code well.
    I commented-out the one that I personally thought did not fit into my codes' context. But, I need your professional opinion.

    //$result = mysqli_stmt_get_result($stmt); //Which line to use ? This line or the next ?

    $result = mysqli_stmt_bind_result($stmt, $db_id, $db_username, $db_password, $db_email, $db_account_activation_status); // Which line to use ? This line or the one above ?


    It is a Log In Page script where the users are given a choice to either login to their accounts by typing their "username" or "email".

    PHP Code:
    <?php
     
    /*
    ERROR HANDLING
    */
    declare(strict_types=1);
    ini_set('display_errors''1');
    ini_set('display_startup_errors''1');
    error_reporting(E_ALL);
    mysqli_report(MYSQLI_REPORT_ERROR MYSQLI_REPORT_STRICT);
     
    include 
    'config.php';
     
    // check if user is already logged in
    if (is_logged() === true
    {
        
    //Redirect user to homepage page after 5 seconds.
        
    header("refresh:2;url=home.php");
        exit; 
    //
    }


    if (
    $_SERVER['REQUEST_METHOD'] == "POST")

        if (isset(
    $_POST["login_username_or_email"]) && isset($_POST["login_password"]))
        {
            
    $username_or_email trim($_POST["login_username_or_email"]); //
            
    $password $_POST["login_password"];        
             
            
    //Select Username or Email to check against Mysql DB if they are already registered or not.
            
    $stmt mysqli_stmt_init($conn);
            
            if(
    strpos("$username_or_email""@"))
            {
                
    $email $username_or_email;
                
    $username "";
                
                
    $query "SELECT ids, usernames, passwords, emails, accounts_activations_statuses FROM users WHERE emails = ?";
                
    $stmt mysqli_prepare($conn$query);            
                
    mysqli_stmt_bind_param($stmt's'$email);
                
    mysqli_stmt_execute($stmt);
                
    //$result = mysqli_stmt_get_result($stmt); //Which line to use ? This line or the next ?
                
    $result mysqli_stmt_bind_result($stmt$db_id$db_username$db_password$db_email$db_account_activation_status); // Which line to use ? This line or the one above ?
            
    }
            else
            {
                
    $username $username_or_email;
                
    $email "";
                
    $query "SELECT ids, usernames, passwords, emails, accounts_activations_statuses FROM users WHERE usernames = ?";
                
    $stmt mysqli_prepare($conn$query);
                
    mysqli_stmt_bind_param($stmt's'$username);
                
    mysqli_stmt_execute($stmt);
                
    //$result = mysqli_stmt_get_result($stmt); //Which line to use ? This line or the next ?
                
    $result mysqli_stmt_bind_result($stmt$db_id$db_username$db_password$db_email$db_account_activation_status); // Which line to use ? This line or the one above ?
            
    }           
            
            
    $row mysqli_stmt_fetch($stmt); //Which line to use ? This line or 2 of the next 2 ?
            
    mysqli_stmt_close($stmt);        
            
    printf("%s (%s)\n",$row["usernames"],$row["passwords"]);
            
            if (
    $result == false)
            {
                echo 
    "No result!";// For debugging purpose!
                
    exit();
            }
            elseif (
    $row['accounts_activations_statuses'] == '0')
            {
                {
                    echo 
    "You have not activated your account yet! Check your email for instructions on how to activate it. 
                    Check your spam folder if you don't find an email from us."
    ;
                    exit();
                }
            }
            else
            {
            
                if (
    password_verify($password$db_password))        
                {
                    echo 
    "IF triggered for password_verify! password_verify ok"// For debugging purpose!
                
                
    $_SESSION["user"] = $username;
                
    header("location:home.php?user=$username");                
            }
            else
            {
                echo 
    "Incorrect User Credentials !';<br>";
                exit();
            }
        }
    }
        
    ?>

    <!DOCTYPE html>
    <html>
    <head>
    <title><?php $site_name?> Member Login Page</title>
      <meta charset="utf-8">
    </head>
    <body>
    <form method="post" action="">
        <h3><?= $site_name ?> Member Login Form</h3>
        <fieldset>
            <label for="login_name">Username/Email:</label>
            <input type="text" name="login_username_or_email" id="login_name" value="">
            <br>
            <label for="login_pass">Password:</label>
            <input type="password" name="login_password" id="login_pass" value="">
        </fieldset>
        <div class="submitsAndHiddens">
            <label for="login_remember">Remember Login Details:</label>
            <input type="checkbox" name="login_remember" />
            <br>
            <button type="submit">Login</button>
            <br>
            <a href="login_password_reset.php">Forgot your Password ? Reset it here!</a>
            <br>
            <a href="register.php">Register here!</a>
        </div>
    </form>

    </body>
    </html>
    Last edited by UniqueIdeaMan; October 4th, 2017 at 07:54 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    307
    Rep Power
    1
    Folks,

    Do you mind reviewing my code in my original post and edit wherever you deem editing is necessary ?
    I prefer versions here on one you use the mysqli_stmt_fetch and on the other mysqli_fetch_array.
    That way, we newbies learn both from you with your examples.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    307
    Rep Power
    1
    Folks,

    I fixed my original post's code tag. So, check the code there now.
    Last edited by UniqueIdeaMan; October 4th, 2017 at 08:11 AM.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Posts
    11
    Rep Power
    0
    Originally Posted by UniqueIdeaMan
    Folks,

    Do you mind reviewing my code in my original post and edit wherever you deem editing is necessary ?
    I prefer 2 versions where on one you use the mysqli_stmt_fetch and on the other mysqli_fetch_array.
    That way, we newbies learn both from you with your examples.
    Perhaps the experts on this forum already know you have received numerous responses on all the OTHER forums you post the exact same questions to.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,342
    Rep Power
    630
    The OP has been advised numerous times before about cross posting to say nothing of using the proper tags for code in posts. In both cases the OP refuses to comply so I, for one, just ignore that OP.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    307
    Rep Power
    1
    Originally Posted by benanamen
    Perhaps the experts on this forum already know you have received numerous responses on all the OTHER forums you post the exact same questions to.
    Oh no! Not you, again! Where've you been hiding my Jack In The Box ? So, you trailed me to this forum ? Lol!
    Since you trailed me here then you might aswell respond to my thread promptly.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    307
    Rep Power
    1
    Originally Posted by gw1500se
    The OP has been advised numerous times before about cross posting to say nothing of using the proper tags for code in posts. In both cases the OP refuses to comply so I, for one, just ignore that OP.
    Sorry, old man! I forgot what you said. It's just on most forums the tag is "code", while here "php". Fixing my threads and so do bother to respond to them promptly.

    Thanks!
    Last edited by UniqueIdeaMan; October 7th, 2017 at 06:13 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,342
    Rep Power
    630
    That's one of the things that happens when you cross-post which, as you know, is greatly frowned upon.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Posts
    11
    Rep Power
    0
    Originally Posted by gw1500se
    That's one of the things that happens when you cross-post which, as you know, is greatly frowned upon.
    Seems UI dude is "frowned upon" on many forums.
    https://www.daniweb.com/community-ce...arns-oldbies/2
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    307
    Rep Power
    1
    [something stupid]
    Last edited by requinix; October 7th, 2017 at 09:00 AM. Reason: tl;dr

IMN logo majestic logo threadwatch logo seochat tools logo