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 3 I should use which will suit the context of my code well.
I commented-out the ones that I personally thought did not fit into my codes' context. But, I need your professional opinion. //Which of the following to use and why that one over the other 2 ?
$row = mysqli_stmt_fetch($stmt); //Which line to use ? This line or 2 of the next 2 ?
//$row = mysqli_fetch_array($query, MYSQLI_ASSOC); //Which line to use ? This line or the one above this lone or the one below this line ?
//$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
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
-
-
/*
-
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 (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_bind_result($stmt, $db_id, $db_username, $db_password, $db_email, $db_account_activation_status);
-
}
-
-
//Which of the following 3 to use and why that one over the other 2 ?
-
$row = mysqli_stmt_fetch($stmt); //Which line to use ? This line or 2 of the next 2 ?
-
//$row = mysqli_fetch_array($query, MYSQLI_ASSOC); //Which line to use ? This line or the one above this lone or the one below this line ?
-
//$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
-
-
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>
-
-
-
1 1672
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jason |
last post by:
Let's say I have an html form with 20 or 30 fields in it. The form
submits the fields via POST to a php page which updates a table in a
database with the $_POST vars. Which makes more sense?
...
|
by: Raymond H. |
last post by:
Hello,
I create a vb4 project which can also naviger on Internet via the
WebBrowser control which I put on my form.
My question is: if this program is installed on a station having already...
|
by: Herman |
last post by:
Hi everyone, I'm currently studying for my Master's in Computer
Science, and I will be working on my thesis this summer. I've been
thinking about constructing a web services application for my...
|
by: CY FOK |
last post by:
Hi
I am planning to open a software company to develop client-server apps and
web applications for my client. Now, i am in a difficult situation to
determine what is the best platform i should use...
|
by: John Bentley |
last post by:
John Bentley:
INTRO
The phrase "decimal number" within a programming context is ambiguous. It could
refer to the decimal datatype or the related but separate concept of a generic
decimal number....
|
by: jason |
last post by:
If you are sending out bulk emails in the range of 800 to 1000 per day
which component is better:
1. ASPEmail
2. CDO
....and further, do they also BOTH use a SEND TO QUEUE option.
I wish...
|
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...
|
by: Skybuck Flying |
last post by:
Hi,
I needed a method to determine if a point was on a line segment in 2D. So I
googled for some help and so far I have evaluated two methods.
The first method was only a formula, the second...
|
by: clintonG |
last post by:
I'm using an .aspx tool I found at but as nice as the interface is I
think I need to consider using others. Some can generate C# I understand.
Your preferences please...
<%= Clinton Gallagher
...
|
by: rn5a |
last post by:
A Form has a select list which is populated from a MS-Access database
table. The DB table from where the select list is populated has 2
columns - CountryID & CountryName. When the Form is posted,...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |