Advertisement
Guest User

Untitled

a guest
May 17th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2.  
  3.     // Get required information
  4.     require_once('db.php');
  5.     require_once('functions.php');
  6.      
  7.     // If session variable is not set it will redirect to login page
  8.     if(!isset($_SESSION['token']) || empty($_SESSION['token'])){
  9.       header("location: /login");
  10.       exit;
  11.     }
  12.  
  13.     # Set variables
  14.    $user = $_SESSION['token'];
  15.     $friends = $friends_err = "";
  16.  
  17.     # Begin SQL
  18.    $sql = "SELECT * FROM `friends` WHERE `user1`='$user'";
  19.     $result = mysqli_query($conn, $sql);
  20.     while($row = mysqli_fetch_assoc($result)) {
  21.         $friends = $row;
  22.     }
  23.  
  24.     if(empty($friends)) {
  25.         $friends_err = "<div class='alert alert-danger' role='alert'>"
  26.                         ."You don't have any friends yet. How sad."
  27.                         ."</div>";
  28.  
  29.     }
  30.  
  31. ?>
  32.  
  33. <?php require_once('header.php'); ?>
  34.  
  35.     <div class="wrapper-base">
  36.         <?php
  37.             echo $friends_err;
  38.  
  39.             if($friends_err == "") {
  40.         ?>
  41.         <strong><p>List of friends</p></strong>
  42.         <?php
  43.             while($row = mysqli_fetch_assoc($result)) {
  44.                 $user = get_data($row['user2']);
  45.                 $date = $row['added'];
  46.  
  47.                 echo "<p><a href='/user/".$user."'>".$user."</a> - <small>added on ".$date."</small></p>";
  48.                 echo "working";
  49.             }
  50.  
  51.             }
  52.         ?>
  53.     </div>
  54.  
  55. <?php require_once('footer.php'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement