How to display current logged information

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
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

ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

<!doctype html>
<html lang="en">
    <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">

// 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'>

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>";


This is for the profile.php

Code: Select all

$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'];

This is for score.php
vRcQu.png (118.57 KiB) Viewed 159 times
This is for profile.php
hGPQu.png (67.87 KiB) Viewed 159 times

User avatar
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");

Post Reply