I'm trying to output the data I have in my database to the screen. All i seem to be getting is a blank screen in Firefox. It doesnt even load the title tags in the html code. Anyone have any idea's ? I'm running PHP 5.3 with WAMP.
The code i use to output the data is :
<?php require_once("db_connect.php"); ?> <html> <head><title>Displaying the Topic database table using PHP</title></head> <body> <h1>Displaying the Topic database table using PHP</h1> <?php /* ------------------------------------------------------------------- //This is the table contents CREATE TABLE topic ( topicID int PRIMARY KEY NOT NULL, userID int FOREIGN KEY NOT NULL, topicName VARCHAR(20) NOT NULL, detail TEXT NOT NULL, time TIMESTAMP NOT NULL, views INT DEFAULT NULL reply INT DEFAULT NULL ); ------------------------------------------------------------------ */ // Connect to server and select a database $db_link = db_connect("forumdod"); // Retrieve table properties $fields = mysql_list_fields("forumdod", "topic"); $num_columns = mysql_num_fields($fields); // Make a simple database query to select all columns and rows $query = "SELECT * FROM topic"; $result = mysql_query($query) or die("SQL query failed"); // Display results as an HTML table. Note how mysql_field name // uses the $fields object to extract the column names echo '<table border="1">', "\n"; // Display the column names echo "<tr>\n"; for ($i = 0; $i < $num_columns; $i++) { echo "<th>", mysql_field_name($fields, $i), "</th>\n"; } echo "</tr>\n"; // Loop over the rows of the table. // $line containsthe the information for each row while ($row = mysql_fetch_assoc($result)) { // Now loop through the entries in each row echo "<tr>\n"; foreach ($row as $col_value) { echo "<td>$col_value</td>\n"; } echo "</tr>\n"; } echo "</table>\n"; // Free the resources and close the connection mysql_free_result($result); mysql_close($db_link); ?> </body> </html>
The code i use to connect to the database definitely works because it works when i use my login script.
I really appreciate all of your help lads, i've been at this for hours.
Thanks,
Dave