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)  
);

along those lines

$query = mysql( $sql );
while ($array = mysql_fetch_array($query)) 
  echo $array['user_name'] . '<br/>';
I am struggling to fetch back the data stored in the database to be view in the system.

This is my code to view all databse after i logged by using the Medicine ID.

<?php

//session_start();
//session_destroy;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<table>
<tr>
<body background="bg2.jpg">
<td><br>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="grey" >
<tr>
<td><br><div align="center"><strong>MEDICINE RECORDS</strong></div></td>
</tr>
<tr>
<td><div align="center"><form action="updatestock2.php"  method="post">
<br><br><td><center><strong></strong></div></td></center> </left>
</tr>

<br><br><br><br>
<form action="updatestock2.php" method="POST">
<br><br>
<td>
<center>Medicine ID:</td><td><input type="text" name="medid"></center> </td>
</tr>


<tr>
<td> <br><br>
<center><input type="reset" value="Reset">
<input type="submit" name="send" value="Send">

</center></td></tr>
<br/><br/> <br/><br/>

</table>
</table>

<table border="3">
<center>
<td align="centre">
<tr> <br><br>
<td>Medicine Name</td>
<td>Total</td>


</tr>
</body>
</html>
<html>
<body>



<?php

  include 'base.php';
  if (isset ($_POST['send']))
{

$medid=$_POST['medid'];

$sql="select * FROM medicine where medid='$medid'";
$result=mysql_query ($sql);


 while($data = mysql_fetch_row($sql))



{

 echo("<tr><td>$data[0]</td><td>$data[1]</td></tr>$data[2]</table>");
}

?> 
<?php
}
?>
</center>
</body>
</html>







I KEEP GETTING THIS ERROR> 
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\fyp3\updatestock2.php on line 70

""

As for the second error, try replacing;

while($data = mysql_fetch_row($sql))

with

while($data = mysql_fetch_row($result))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.