John Davidson

php - Displaying the full name instead of full name

0 comments
Message:


My login table has Username and Password fields. I want to display the user's full name rather than their username when they log in with their username and password. Instead of saying Welcome USERNAME on the next page, I want to say Welcome FULLNAME.


Here is the index.php or the login page in html:


 <form action="" method="POST">
<div class="rows grid">

<div class="row">
<label for="username">User Name</label>
<input type="text" id="username" name="userName" placeholder="Enter Username" required>
</div>
<!--Password-->
<div class="row">
<label for="password">Password</label>
<input type="password" id="password" name="passWord" placeholder="Enter Password" required>
</div>
<!--Submit Button-->
<div class="row">
<input type="submit" id="submitBtn" name="submit" value="Login" required>
<!--Register Link-->
<span class="registerLink">Don't have an account? <a href="register.php">Register</a></span>
</div>
</div>
</form>
</div>
</div>

Here is the php:


<?php
// Submit
if(isset($_POST['submit'])){
// Store the names, password, email, number
$userName = $_POST['userName'];
$passWord = $_POST['passWord'];
// Selecting from database
$sql = "SELECT * FROM admin WHERE
usernames = '$userName' AND
passwords = '$passWord'";
// Exceute the query
$result = mysqli_query($conn, $sql);
// Count the number of the account of the same username and password
$count = mysqli_num_rows($result);
// Counts the results into arrys
$row = mysqli_fetch_assoc($result);
// Check if theres account in database
if ($count == 1){
$_SESSION['loginMessage'] = '<span class = "success">Welcome '.$userName.'</span>';
header('location:' .SITEURL. 'dashboard.php');
exit();
}
else{
$_SESSION['noAdmin'] = '<span class = "fail">Please check your username and password and try again.</span>';
header('location:' .SITEURL. 'index.php');
exit();
}
}
?>

Here is the register.php or register link:


<form action="" method="POST">
<div class="rows grid">
<!--Full Name-->
<div class="row">
<label for="fullname">Full Name</label>
<input type="text" id="fullname" name="fullName" placeholder="Enter Full Name" required>
</div>
<!--Username-->
<div class="row">
<label for="username">User Name</label>
<input type="text" id="username" name="userName" placeholder="Enter Username" required>
</div>
<!--Email-->
<div class="row">
<label for="email">Email</label>
<input type="email" id="email" name="emaiL" placeholder="Enter Email" required>
</div>
<!--Mobile Number-->
<div class="row">
<label for="number">Mobile Number</label>
<input type="number" id="number" name="numbeR" placeholder="Enter Mobile Number" required>
</div>
<!--Password-->
<div class="row">
<label for="password">Password</label>
<input type="password" id="password" name="passWord" placeholder="Enter Password" required>
</div>
<!--Submit Button-->
<div class="row">
<input type="submit" id="submitBtn" name="submit" value="Register" required>
<!--Try ko aban aban uni idelete-->
<span class="registerLink">Have an account already? <a href="index.php">Login</a></span>
</div>
</div>
</form>

Note: I want to display the input fullname in the welcome dashboard.



My Answer:
To display the user's full name instead of their username on the welcome dashboard, you need to modify the PHP code in your index.php file. Here's how you can do it:

1. Update the SQL query to fetch the full name along with the username and password:
php
$sql = "SELECT * FROM admin WHERE
usernames = '$userName' AND
passwords = '$passWord'";


2. Modify the code to store the full name in a variable and use it in the welcome message:
php
// Store the full name
$fullName = $row['fullname'];

// Check if there is an account in the database
if ($count == 1){
$_SESSION['loginMessage'] = 'Welcome '.$fullName.'';
header('location:' .SITEURL. 'dashboard.php');
exit();
}


By making these changes, the welcome message on the dashboard will display the user's full name instead of their username. Make sure to also update your database table to include the full name field if it's not already there.

Rate this post

4 of 5 based on 1872 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us