Wednesday, January 19, 2022

[FIXED] php Session PHP getting data related to user

Issue

Anyway im trying to connect my database so that it will only show information related to the user, but no matter where i look or see for this information, its either outdated or not relevant to me. Could i get some help on trying to confirm the confirmation

<?php if (isset($_SESSION['username'])) : ?>
<t>
<p>Username: <strong><?php echo $_SESSION['username']; ?></strong></p>

<?php endif ?>

<?php

$query = "SELECT * FROM `confirm`;";
$result = mysqli_query($db, $query);
$resultCheck = mysqli_num_rows($result);

if ($resultCheck > 0) { 
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['food'] , "<br>";
 }
}

?>

Solution

Of you want to fetch user specific information then you need to add a where clause in your sql query. Something like

$name=$_SESSION[‘username’]; 
$query = "SELECT * FROM `confirm` where name=‘$name’;";


Answered By - Parth Manaktala

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.