title: Accessing database and display registered users through PHP
body: <p>I have a members.php page/file in which i want logged in users to see the other users registered in the database. I'm not exactly quite sure how to do this and I'm struggling quite a while now with this so your help will be VERY much appreciated.</p>
  
  <p>I will include connect.php, members.php and my database.sql </p>
  
  <p><strong>Here is my connect.php file</strong></p>
  
  <pre><code>&lt;?php 
  session_start();
  //connect.php
  
  $server = 'localhost';
  $username = 'root';
  $password = '';
  $database = 'mydatabase';
  
  if(!mysql_connect('localhost', 'root', ''))
  {
  exit('Error: could not establish database connection');
  }
  if(!mysql_select_db($database))
  {
  exit('Error: could not select the database');
  }
  ?&gt;
  </code></pre>
  
  <p><strong>Here is my members.php file</strong></p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;head&gt;
  &lt;title&gt; ShareLink &lt;/title&gt;
  &lt;link rel="stylesheet" href="style.css" type="text/css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="wrapper"&gt;
      &lt;?php
  
      //create_cat.php
      include 'connect.php';
      include 'header.php';
  
      if(isset($_SESSION['signed_in']) == FALSE || isset($_SESSION['user_level']) != 1 )
          {
              //the user IS NOT an admin
              echo '&lt;br/&gt;';
              echo 'Sorry! You have to be &lt;a href="/signin.php"&gt;&lt;b&gt;logged in&lt;/b&gt;&lt;/a&gt; to view all the &lt;a href="signup.php" title="Become a registered user!"&gt;&lt;b&gt;registered&lt;/b&gt;&lt;/a&gt; members.';
              echo '&lt;br/&gt;&lt;br/&gt;';
          }
          ELSE
          {
              echo '&lt;h2&gt;Registered users:&lt;/h2&gt;';
  
              $sql = "SELECT user_name FROM users";
  
              //NOW I WANT TO DISPLAY ALL THE REGISTERED USERS
  
              //MUST I ECHO SOMETHING HERE?
  
              /////////////////////////////////////////////////////////
              ///////////////  WHAT CODE MUST COME HERE? //////////////
              /////////////// AND IS IT SQL OR PHP CODE? //////////////
              /////////////////////////////////////////////////////////
          }
          include 'footer.php';
      ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p><strong>Here is my database.sql file</strong></p>
  
  <pre><code>CREATE TABLE users (  
  user_id     INT(8) NOT NULL AUTO_INCREMENT,  
  user_name   VARCHAR(30) NOT NULL,  
  user_pass   VARCHAR(255) NOT NULL,  
  user_email  VARCHAR(255) NOT NULL,  
  user_date   DATETIME NOT NULL,  
  user_level  INT(8) NOT NULL,  
  UNIQUE INDEX user_name_unique (user_name),  
  PRIMARY KEY (user_id)  
  );
  
  CREATE TABLE categories (  
  cat_id          INT(8) NOT NULL AUTO_INCREMENT,  
  cat_name        VARCHAR(255) NOT NULL,  
  cat_description     VARCHAR(255) NOT NULL,  
  UNIQUE INDEX cat_name_unique (cat_name),  
  PRIMARY KEY (cat_id)    
  );
  
  CREATE TABLE topics (  
  topic_id        INT(8) NOT NULL AUTO_INCREMENT,  
  topic_subject       VARCHAR(255) NOT NULL,  
  topic_date      DATETIME NOT NULL,  
  topic_cat       INT(8) NOT NULL,  
  topic_by        INT(8) NOT NULL,  
  PRIMARY KEY (topic_id)  
  ); 
  
  CREATE TABLE posts (  
  post_id         INT(8) NOT NULL AUTO_INCREMENT,  
  post_content        TEXT NOT NULL,  
  post_date       DATETIME NOT NULL,  
  post_topic      INT(8) NOT NULL,  
  post_by     INT(8) NOT NULL,  
  PRIMARY KEY (post_id)  
  );
  </code></pre>