aquilina Posted May 26, 2016 Share Posted May 26, 2016 Hello. I have a problem in displaying the user data form database which associated with the user. Maybe i'm messing up the _SESSION part. Im stucked at this part when im changing the add_parcel send_to attribute from (student_username) to (student_name). Since i wanted to display the name of student not the username. <?php session_start(); if(!($_SESSION['username'])){ header("location:index.php?login_first"); } ?> <!-- end navbar top --> <?php include("sidemenu.php"); ?> <!-- page-wrapper --> <div id="page-wrapper"> <div class="row"> <!-- Page Header --> <div class="col-lg-12"> <h1 class="page-header">Dashboard</h1> </div> <!--End Page Header --> </div> <div class="row"> <!-- Welcome --> <div class="col-lg-12"> <div class="alert alert-info"> <?php include("connection.php"); $username=$_SESSION['username']; $sql=mysql_query("SELECT student_name FROM register WHERE student_username='$username'"); $ee=mysql_fetch_array($sql); ?> <i class="fa fa-folder-open"></i><b> Hello ! </b>Welcome Back <b><?php echo $ee['student_name']; ?> </b> </div> </div> <!--end Welcome --> </div> <div class="row"> <div class="col-lg-12"> <div class="table table-responsive"> <table class="table table-hover"> <thead> <tr> <th>S.no</th> <th>Parcel Number</th> <th>Date Recieved</th> <th>Date of Collected</th> <th>Recieved Time</th> <th>Collect Time</th> <th>Status</th> <th>Sent By</th> <th>Sent To</th> </tr> </thead> <?php include("connection.php"); $sql1=mysql_query("SELECT * FROM add_parcel WHERE send_to='$username'"); $i=1; while($row=mysql_fetch_array($sql1)){ echo '<tr class="record"><td>'.$i++.'</td><td>'.$row['parcel_num'].'</td><td>'.$row['date_recieve'].'</td><td>'.$row['date_collect'].'</td><td>'.$row['recieve_time'].'</td><td>'.$row['collect_time'].'</td><td>'.$row['status'].'</td><td>'.$row['sender_name'].'</td><td>'.$row['send_to'].'</td></tr>'; } ?> </html> I tried to change the below code $sql1=mysql_query("SELECT * FROM add_parcel WHERE send_to='$username'"); to $sql1=mysql_query("SELECT * FROM add_parcel"); it displayed all the data of table. I will attach together with some screenshot as well to make it easier.below is image of the Dashboard of user (Screenshot_1 (1).png). Add parcel panel (Screenshot_1 (2).png) Table add_parcel (Screenshot_1 (3).png) Table register (Screenshot_1 (4).png) Quote Link to comment https://forums.phpfreaks.com/topic/301264-data-of-user-called-does-not-appear/ Share on other sites More sharing options...
mac_gyver Posted May 26, 2016 Share Posted May 26, 2016 in one of the other php help sites you posted this on, someone went to the trouble of figuring out what the problem is and posted a reply. you are mixing up the student_username and student_name values. i suggest you read existing replies you have before posting your problem elsewhere. Quote Link to comment https://forums.phpfreaks.com/topic/301264-data-of-user-called-does-not-appear/#findComment-1533260 Share on other sites More sharing options...
aquilina Posted May 26, 2016 Author Share Posted May 26, 2016 in one of the other php help sites you posted this on, someone went to the trouble of figuring out what the problem is and posted a reply. you are mixing up the student_username and student_name values. i suggest you read existing replies you have before posting your problem elsewhere. Im looking for the explaination which can make me easier to understand. im try to understand the previous post, but i cannt Quote Link to comment https://forums.phpfreaks.com/topic/301264-data-of-user-called-does-not-appear/#findComment-1533262 Share on other sites More sharing options...
Psycho Posted May 26, 2016 Share Posted May 26, 2016 Im looking for the explaination which can make me easier to understand. im try to understand the previous post, but i cannt So, instead of asking for clarification on the response you were given in another forum, you decided to ask the same question on a different forum. But, I will give you this advice: $username=$_SESSION['username']; $sql=mysql_query("SELECT student_name FROM register WHERE student_username='$username'"); $ee=mysql_fetch_array($sql); ?> <i class="fa fa-folder-open"></i><b> Hello ! </b>Welcome Back <b><?php echo $ee['student_name']; ?> </b> If you want to display the student_name on every/most page(s), then you should be storing that in the session data so you don't need to do a query just to show that data. Quote Link to comment https://forums.phpfreaks.com/topic/301264-data-of-user-called-does-not-appear/#findComment-1533263 Share on other sites More sharing options...
mac_gyver Posted May 26, 2016 Share Posted May 26, 2016 to save anyone from wasting time replying with problems in this code, the OP has already been told - 1) what the main problem is, which should be enough to make the code 'work', especially if he is aware of or is looking at what data is being storing in the database tables, which, sorry for the cutting commentary, the OP apparently isn't aware of or looking at. 2) to use the id of the source data when storing related data in other tables, i.e properly implement the R in RDBMS. 3) to have an exit statement after the header() redirect. 4) about the obsolete mysql statements, and to use PDO with prepared queries to securely get data values into the sql query. some other things to mention are - 1) don't include your database connection file more than once in the code. 2) separate the database code, that's retrieving data, from the presentation code, that's using the data to produce the output. doing this will actually make it easier to rewrite the code to replace the mysql statements with something more current. Quote Link to comment https://forums.phpfreaks.com/topic/301264-data-of-user-called-does-not-appear/#findComment-1533264 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.