Hey everyone!
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.
I will include connect.php, members.php and my database.sql
Here is my connect.php file
<?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');
}
?>
Here is my members.php file
<!DOCTYPE HTML>
<head>
<title> ShareLink </title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div id="wrapper">
<?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 '<br/>';
echo 'Sorry! You have to be <a href="/signin.php"><b>logged in</b></a> to view all the <a href="signup.php" title="Become a registered user!"><b>registered</b></a> members.';
echo '<br/><br/>';
}
else
{
echo '<h2>Registered users:</h2>';
$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';
?>
</div>
</body>
</html>
Here is my database.sql file
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)
);