How to display current logged information

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Adasisi
New php-forum User
New php-forum User
Posts: 1
Joined: Fri May 18, 2018 1:42 pm

Fri May 18, 2018 1:56 pm

In this part of the code, both the score table, and the profile page display everything I want, however it is displaying EVERYBODIES details rather than the logged in users details.


This is for the score.php

Code: Select all


  <?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
require("db_connect.php");
session_start();
?>

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../../../favicon.ico">

<?php
$con=mysqli_connect("localhost","username","Password","Database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


$result = mysqli_query($con,"SELECT * FROM Score where 'Username' LIKE _['Username']");


echo "<table border='1'>
<tr>
<th>ID</th>
<th>Username</th>
<th>Score</th>
<th>Gamedate</th>
<th>QuizTitle</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Username'] . "</td>";
echo "<td>" . $row['Score'] . "</td>";
echo "<td>" . $row['Gamedate'] . "</td>";
echo "<td>" . $row['QuizTitle'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

This is for the profile.php

Code: Select all


 <?php
 require('db_connect.php');
$result = mysqli_query($conn,"SELECT *FROM Users ");
while($row = mysqli_fetch_array($result))
{
       echo "<br />Your <b><i>Profile</i></b> is as follows:<br />";
        echo "<b>First name:</b> ". $row['FirstName'];
        echo "<br /><b>Last name:</b> ".$row['Surname'];
        echo "<br /><b>Email:</b> ".$row['Email'];
        echo "<br /><b>Year:</b> ".$row['Username'];
        echo "<br /><b>Date created :</b> ".$row['Date_Creation'];
}
mysqli_close($conn);
?>
    </main>



</html>
Attachments
vRcQu.png
This is for score.php
vRcQu.png (118.57 KiB) Viewed 159 times
hGPQu.png
This is for profile.php
hGPQu.png (67.87 KiB) Viewed 159 times

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 708
Joined: Mon Feb 22, 2016 5:52 pm

Fri May 18, 2018 11:45 pm

however it is displaying EVERYBODIES details
It is returning what you have asked for, change the SQL, and I strongly recommend using prepared statements while you go about making your changes, the point in using prepared statements was to improve security.

Code: Select all

$stmt = $con->prepare("SELECT *FROM Users");
$stmt->execute();

Post Reply