I want to create a welcome page for the user who logged into the site.
My difficulty is in creating the query as I do it and show the user name through an echo?
login.php form
<?php
session_start();
if(isset($_POST['submit'])){
$user = $_POST['username'];
$pwrd = $_POST['pwrd'];
//include database connection
include('includes/db_connect.php');
if(empty($user) || empty($pwrd)){
echo 'Nada informado';
}else{
//prevenção de sql injection
$user = strip_tags($user);
$user = $db->real_escape_string($user);
$pwrd = strip_tags($pwrd);
$pwrd = $db->real_escape_string($pwrd);
$pwrd = md5($pwrd);
$query = $db-> query("SELECT user_id, username FROM user WHERE username='$user' AND password='$pwrd'");
//echo $query->num_rows; ver se tem algo no banco
if($query->num_rows === 1){
while($row = $query->fetch_object()){
$_SESSION['user_id'] = $row->user_id;
}
header('Location: admin/index.php');
exit();
}else{
echo 'Nada informado';
}
}
}
?>
index.php welcome page
<?php
include('../includes/db_connect.php');
$query = $db-> query("SELECT user_id, username FROM user WHERE username='$user'");
echo 'bem vindo: $ não sei o que colocar aqui';
?>
-index.php-thisiswhatIwanttohappen,gettheloginusernameanddisplayitonawelcomescreen.