Load data using _session in php

rsbypi4

New member
I want to load my data from database using _session in php, but it's not working properly. I don't know also if my code have a problem.

PHP:
<?php
                    $aid=$_SESSION['u_id'];
                    $ret="SELECT * FROM tbl_student WHERE u_id=? ";
                    $stmt= $mysqli->prepare($ret) ;
                    $stmt->bind_param('i',$aid);
                    $stmt->execute() ;
                    $res=$stmt->get_result();
                        while($row=$res->fetch_object())
                        {
                ?>
                  <tr>
                    <td style="min-width: 200px;" class="text-center"><?php echo $row->student_name;?></td>
                    <td style="min-width: 200px;" class="text-center"><?php echo $row->contact_num;?></td>
                    <td style="min-width: 200px;" class="text-center"><?php echo $row->address;?></td>
                    
                     ?>
                     </td>
            

                  </tr>

                <?php  }?>

My problem is cannot fetch the data base on the session.
 
I want to load my data from database using _session in php, but it's not working properly. I don't know also if my code have a problem.

PHP:
<?php
                    $aid=$_SESSION['u_id'];
                    $ret="SELECT * FROM tbl_student WHERE u_id=? ";
                    $stmt= $mysqli->prepare($ret) ;
                    $stmt->bind_param('i',$aid);
                    $stmt->execute() ;
                    $res=$stmt->get_result();
                        while($row=$res->fetch_object())
                        {
                ?>
                  <tr>
                    <td style="min-width: 200px;" class="text-center"><?php echo $row->student_name;?></td>
                    <td style="min-width: 200px;" class="text-center"><?php echo $row->contact_num;?></td>
                    <td style="min-width: 200px;" class="text-center"><?php echo $row->address;?></td>
                  
                     ?>
                     </td>
          

                  </tr>

                <?php  }?>

My problem is cannot fetch the data base on the session.
Where exactly are you creating your session variables? For example, where is $_SESSION['u_id'] being defined? Also, where are you starting your session? session_start()
 
Where exactly are you creating your session variables? For example, where is $_SESSION['u_id'] being defined? Also, where are you starting your session? session_start()
Good day Moorcam, Thank you for your reply. I already fix my issue base what you message to me. My main problem in $_SESSION where is I call u_id which is a primary key. Now during calling to the other table, example tbl_1 and tbl_2 have a u_id columns but not the same entity, that's why I make another columns which is the same column name and the same entity.
 
Good day Moorcam, Thank you for your reply. I already fix my issue base what you message to me. My main problem in $_SESSION where is I call u_id which is a primary key. Now during calling to the other table, example tbl_1 and tbl_2 have a u_id columns but not the same entity, that's why I make another columns which is the same column name and the same entity.
Glad you got it sorted.
 
Back
Top