I will help you how to select data from a database using session variable. Select data from database using session variable in PHP web application. I will give a example with code that you will fetch data from database using Session variable in PHP.
You need to connect the database in your web page, where you fetch the data From Mysql database using session variable. Then start the session, that’s like session_start(). Now select data from database using this code $_SESSION[’user_id’]. The user_id is the session variable, you will put the session variable here, which variable name you set in the session.
Example Code:
<?php include 'db_connect.php'; session_start(); $sql=mysqli_query($mysqli,"SELECT * FROM `Table Name` WHERE `user_id`='".$_SESSION['user_id'];."'"); $row=mysqli_fetch_array($sql); ?>
Question and answer is powered by AnsPress.io