Hi,
I have a database with some columns, two of them are username and password, the other columns are information from the customer… After login i’m having difficulty retrieving data from the other columns than userame.
With the code below I can only present the username in the dashboard. How should I proceed so that I can retrieve the info in the other columns?
Thank you for the help!!
LOGIN PAGE:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>LSC</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<?php
require('db.php');
session_start();
// When form submitted, check and create user session.
if (isset($_POST['username'])) {
$username = stripslashes($_REQUEST['username']); // removes backslashes
$username = mysqli_real_escape_string($con, $username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con, $password);
// Check user is exist in the database
$query = "SELECT * FROM `users` WHERE username='$username'
AND password='$password'";
$result = mysqli_query($con, $query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if ($rows == 1) {
$_SESSION['username'] = $username;
// Redirect to user dashboard page
header("Location: dashboard.php");
} else {
echo "<div class='form'>
<h3>Incorrect Username/password.</h3><br/>
<p class='link'>Click here to <a href='login.php'>Login</a> again.</p>
</div>";
}
} else {
?>
<form class="forminicial" method="post" name="login">
<h1 class="login-title">LSC</h1>
<input type="text" class="login-input" name="username" placeholder="ID da denúncia" autofocus="true"/>
<input type="password" class="login-input" name="password" placeholder="Palavra-Passe"/>
<input type="submit" value="Entrar" name="submit" class="login-button"/>
<p class="link">...</p>
</form>
<?php
}
?>
</body>
</html>
DASHBOARD
<?php
//include auth_session.php file on all user panel pages
include("auth_session.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>LSC</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="form">
<h1 class="login-title">LSC</h1>
<p>ID de Denúncia: <?php echo $_SESSION['username']; ?>!</p>
<p>Categoria da Denúncia:</p>
<p><a href="../index.php">Sair</a></p>
</div>
</body>
</html>
AUTH_SESSION
<?php
session_start();
if(!isset($_SESSION["username"])) {
header("Location: login.php");
exit();
}
?>`