Getting Blank Page...

... when using my script to output database data

Page 1 of 1

11 Replies - 1500 Views - Last Post: 06 December 2009 - 02:52 PM Rate Topic: -----

#1 DeWire   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-December 08

Getting Blank Page...

Posted 05 December 2009 - 10:23 AM

Hi lads,

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

Is This A Good Question/Topic? 0
  • +

Replies To: Getting Blank Page...

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,941
  • Joined: 08-August 08

Re: Getting Blank Page...

Posted 05 December 2009 - 11:36 AM

What's in: db_connect.php?
You could check the php_error.log file for error messages.
Was This Post Helpful? 0
  • +
  • -

#3 DeWire   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-December 08

Re: Getting Blank Page...

Posted 05 December 2009 - 12:13 PM

<?php
function db_connect($db_name)
{
   $host_name = "localhost";
   $user_name = "root";
   $password = "";
   $db_link = mysql_connect($host_name, $user_name, $password)
	  or die("Could not connect to $host_name");
   mysql_select_db($db_name)
	  or die("Could not select database $db_name");
   return $db_link;
}
?>



The code above is what i have in db_connect.php .

Thanks,
Dave

This post has been edited by DeWire: 05 December 2009 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,941
  • Joined: 08-August 08

Re: Getting Blank Page...

Posted 05 December 2009 - 04:52 PM

I don't see any obvious errors. Does the code do anything with the require commented out? If the require fails, it will stop execution.
Was This Post Helpful? 0
  • +
  • -

#5 DeWire   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-December 08

Re: Getting Blank Page...

Posted 05 December 2009 - 06:04 PM

If i Comment out the require_once tag, i get the heading "Displaying the Topic database table using PHP"

Thanks for your time.
Any other ideas?

Thanks again,
Dave
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,941
  • Joined: 08-August 08

Re: Getting Blank Page...

Posted 05 December 2009 - 06:40 PM

It looks to me like the require is failing. Is the file: db_connect.php in the same directory as your code?
Was This Post Helpful? 0
  • +
  • -

#7 DeWire   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-December 08

Re: Getting Blank Page...

Posted 06 December 2009 - 06:13 AM

Yep - db_connect is in the same directory.... :( It's been wreckin my head for days now - i cant figure this out.... :(

Dave
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Getting Blank Page...

Posted 06 December 2009 - 07:18 AM

Have you got error logging turned on in your php.ini? Like CTphpnwb suggested way back, you can check your error logs if you do. If you do NOT, I would suggest to turn them on, try again, and check the log.
Was This Post Helpful? 0
  • +
  • -

#9 DeWire   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-December 08

Re: Getting Blank Page...

Posted 06 December 2009 - 08:43 AM

View PostJackOfAllTrades, on 6 Dec, 2009 - 06:18 AM, said:

Have you got error logging turned on in your php.ini? Like CTphpnwb suggested way back, you can check your error logs if you do. If you do NOT, I would suggest to turn them on, try again, and check the log.

Hi mate,

Still getting a blankpage :(
Dont know what to do .... Any other ideas? :(

Thanks,
Dave
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Getting Blank Page...

Posted 06 December 2009 - 08:54 AM

Are you actually READING what people write? You've got error logging on? Is there an error log being created? Is there anything in it? Might you post it here?

Don't be daft and just keep coming back with...blank page, blank page, blank page.
Was This Post Helpful? 0
  • +
  • -

#11 DeWire   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-December 08

Re: Getting Blank Page...

Posted 06 December 2009 - 01:28 PM

Apologies,

Didn't mean to be short with you.
I have error checking turned on, but there is no file in the wamp logs directory where php.ini is set to save the error log file.

I tested the my code using a different database and table on a different server - it worked.
So with that in mind, have you any idea what could cause the problem ?

Thanks,
Dave

This post has been edited by DeWire: 06 December 2009 - 02:52 PM

Was This Post Helpful? 0
  • +
  • -

#12 Keiran   User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 06-December 09

Re: Getting Blank Page...

Posted 06 December 2009 - 02:52 PM

maybe your database and or table doesnt exist and is causing the mysql_select_db to fail.

Make sure you type the database in the case it is on the mySQL server

e.g

forumdod != ForumDOD

on a further note

make sure php.ini has the following

display_errors = On

its set to Off by default

This post has been edited by Keiran: 06 December 2009 - 02:53 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1