473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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".

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. /*
  5. ERROR HANDLING
  6. */
  7. declare(strict_types=1);
  8. ini_set('display_errors', '1');
  9. ini_set('display_startup_errors', '1');
  10. error_reporting(E_ALL);
  11. mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  12.  
  13. include 'config.php';
  14.  
  15. // check if user is already logged in
  16. if (is_logged() === true) 
  17. {
  18.     //Redirect user to homepage page after 5 seconds.
  19.     header("refresh:2;url=home.php");
  20.     exit; //
  21. }
  22.  
  23.  
  24. if ($_SERVER['REQUEST_METHOD'] == "POST")
  25.     if (isset($_POST["login_username_or_email"]) && isset($_POST["login_password"]))
  26.     {
  27.         $username_or_email = trim($_POST["login_username_or_email"]); //
  28.         $password = $_POST["login_password"];        
  29.  
  30.         //Select Username or Email to check against Mysql DB if they are already registered or not.
  31.         $stmt = mysqli_stmt_init($conn);
  32.  
  33.         if(strpos("$username_or_email", "@"))
  34.         {
  35.             $email = $username_or_email;
  36.             $username = "";
  37.  
  38.             $query = "SELECT ids, usernames, passwords, emails, accounts_activations_statuses FROM users WHERE emails = ?";
  39.             $stmt = mysqli_prepare($conn, $query);            
  40.             mysqli_stmt_bind_param($stmt, 's', $email);
  41.             mysqli_stmt_execute($stmt);
  42.             //$result = mysqli_stmt_get_result($stmt); //Which line to use ? This line or the next ?
  43.             $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 ?
  44.         }
  45.         else
  46.         {
  47.             $username = $username_or_email;
  48.             $email = "";
  49.             $query = "SELECT ids, usernames, passwords, emails, accounts_activations_statuses FROM users WHERE usernames = ?";
  50.             $stmt = mysqli_prepare($conn, $query);
  51.             mysqli_stmt_bind_param($stmt, 's', $username);
  52.             mysqli_stmt_execute($stmt);
  53.             //$result = mysqli_stmt_get_result($stmt); //Which line to use ? This line or the next ?
  54.             $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 ?
  55.         }           
  56.  
  57.         $row = mysqli_stmt_fetch($stmt); //Which line to use ? This line or 2 of the next 2 ?
  58.         mysqli_stmt_close($stmt);        
  59.         printf("%s (%s)\n",$row["usernames"],$row["passwords"]);
  60.  
  61.         if ($result == false)
  62.         {
  63.             echo "No result!";// For debugging purpose!
  64.             exit();
  65.         }
  66.         elseif ($row['accounts_activations_statuses'] == '0')
  67.         {
  68.             {
  69.                 echo "You have not activated your account yet! Check your email for instructions on how to activate it. 
  70.                 Check your spam folder if you don't find an email from us.";
  71.                 exit();
  72.             }
  73.         }
  74.         else
  75.         {
  76.  
  77.             if (password_verify($password, $db_password))        
  78.             {
  79.                 echo "IF triggered for password_verify! password_verify ok"; // For debugging purpose!
  80.  
  81.             $_SESSION["user"] = $username;
  82.             header("location:home.php?user=$username");                
  83.         }
  84.         else
  85.         {
  86.             echo "Incorrect User Credentials !';<br>";
  87.             exit();
  88.         }
  89.     }
  90. }
  91.  
  92. ?>
  93.  
  94. <!DOCTYPE html>
  95. <html>
  96. <head>
  97. <title><?php $site_name?> Member Login Page</title>
  98.   <meta charset="utf-8">
  99. </head>
  100. <body>
  101. <form method="post" action="">
  102.     <h3><?= $site_name ?> Member Login Form</h3>
  103.     <fieldset>
  104.         <label for="login_name">Username/Email:</label>
  105.         <input type="text" name="login_username_or_email" id="login_name" value="">
  106.         <br>
  107.         <label for="login_pass">Password:</label>
  108.         <input type="password" name="login_password" id="login_pass" value="">
  109.     </fieldset>
  110.     <div class="submitsAndHiddens">
  111.         <label for="login_remember">Remember Login Details:</label>
  112.         <input type="checkbox" name="login_remember" />
  113.         <br>
  114.         <button type="submit">Login</button>
  115.         <br>
  116.         <a href="login_password_reset.php">Forgot your Password ? Reset it here!</a>
  117.         <br>
  118.         <a href="register.php">Register here!</a>
  119.     </div>
  120. </form>
  121.  
  122. </body>
  123. </html>
  124.  
  125.  
Sep 29 '17 #1
1 1612
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_get_result and on the other mysqli_stmt_bind_result.
That way, we newbies learn both from you with your examples.
Oct 1 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Rob Martin | last post by:
Greetings There seems to be two main ways of creating PDF from java - 1. via HTML to PDF and 2. using an API (e.g. iText). What are your thoughts - is there an adopted 'standard' method of the...
7
by: Murtix Van Basten | last post by:
Hi all, I will deploy a database project to an Oracle server, but I could not figure out which version of Oracle should I get. Here is my configuration: Hardware: Dell 1750 Dual Xeon 3.2Ghz,...
17
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this...
10
by: Newry | last post by:
Hi, If you have both this HTTP header: Content-Type: text/html; charset=ISO-8859-1 and this HTML element in the <head>: <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
0
by: Nak | last post by:
Hi there, I'm slightly confused regarding the purpose of this method "SetSaveLicenseKey" which is part of the LicenseContext object. I had first presumed that it was used to "cache" a license...
13
by: cat_dog_ass | last post by:
Java is mature...however, a beginner may not stand any chance to compete against industry bigwigs. On the other hand, .NET is newer and gives newbies a relatively firm foothold, since there are...
4
by: eejit | last post by:
Another newbie question. I'm writing a program that reviews a text file history of an online poker hand. I'm using VB compact framework, for a pocket pc. I'm trying to find a simple way to...
1
by: dizzy | last post by:
My client application will have a set of varying business functions. These functions will be fullfiled via various 3rd party services (i.e. web services, http post/get, remote data access or socket...
84
by: Patient Guy | last post by:
Which is the better approach in working with Javascript? 1. Server side processing: Web server gets form input, runs it into the Javascript module, and PHP collects the output for document prep....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.