I messed up - the database is empty

Edit: included code

I was trying to organize the files for my project and after getting all the folders organized and all the file paths correct, my page now diplays “the database is empty”.

index.php

<?php 

		include("http://localhost/myproject/php/connect.php"); 

		$query    = "SELECT * FROM table ORDER BY firstgroup"; 
		$result = mysql_query($query); 
		$num    = mysql_num_rows ($result); 
		mysql_close(); 

		$i = 0; 

		if ($num > 0) 
		{ 
			echo '<table class="table1">';
			 echo '<thead>'; 
			     echo '<tr>'; 
			     echo "<td><a href='http://localhost/mywebsite/groupa.php'>Group A:</a></td>"; 
			     echo "<td><a href='http://localhost/mywebsite/groupb.php'>Group B:</a></td>"; 
			     echo "<td><a href='http://localhost/mywebsite/groupc.php'>Group C</a></td>"; 
			     echo "<td><a href='http://localhost/mywebsite/groupd.php'>Group D:</a></td>"; 
			     echo "</tr>";
				 echo '</thead>';

			    while ($i < $num) 
			    { 
			        $typea    = mysql_result($result,$i,"typea"); 
			        $typeb     = mysql_result($result,$i,"typeb"); 
			        $typec    = mysql_result($result,$i,"typec"); 
			        $typed    = mysql_result($result,$i,"typed"); 
			        $id            = mysql_result($result,$i,"id"); 

			        echo '<tr>'; 
			        echo "<td>$typea</td>"; 
			        echo "<td>$typeb</td>"; 
			        echo "<td>$typec</td>"; 
			        echo "<td>$typed</td>";  
			        echo "</tr>"; 

			        ++$i; 
			    } 

			    echo '</table>';
		} 
		else 
		echo "The database is empty"; 

		?>

connect.php

<?php
/// For the following details,
/// please contact your server vendor

$hostname='localhost'; //// specify host, i.e. 'localhost'
$user='root'; //// specify username
$pass='mypass'; //// specify password
$dbase='project'; //// specify database name
$connection = mysql_connect("$hostname" , "$user" , "$pass") 
or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");
?>

The problem is that I’m not getting an error about connecting to the database and all the file paths are correct.

I have another project running the same database and index.php page and connect.php and has the same include for the connect.php page (file path is different). This project can still pull the data from the database.

I copied the index page from the working project over to my other one and just fixed the path to the connect.php. And now it says “the database is empty.”

I can’t figure out what went wrong…I didn’t change the connect.php file nor the actual php script to pull from the database.

Any ideas?

Thanks

Haha sorry. I’m in a bit of a rush.

table is a reserved word, try the following query.


SELECT * FROM `table` ORDER BY firstgroup

Note the quoted reserved word using backticks.

Tried it, but no fix.

How about you post the code prior to the ‘else’, specifically the ‘if’ ? :stuck_out_tongue:

Awesome, got it working again. Thanks!

Your using a URL for the include, which means it gets parsed by the webserver and you’re including the output - which is nothing.

Use a local path, such as ‘’/myproject/php/connect.php" or “/usr/anthony/web/myproject/php/connect.php”