Computing.Net > Forums > Web Development > PHP blank page

PHP blank page

Reply to Message Icon

Original Message
Name: ChromeShark (by croftstorm)
Date: February 9, 2007 at 09:39:47 Pacific
Subject: PHP blank page
OS: windows xp
CPU/Ram: 512mb
Model/Manufacturer: Compaq
Comment:

This seems like a simple PHP MySQL problem, but it has me stumped.

The page has the following php code:

<?
$query = "SELECT * FROM test";
$result = mysql_query($query);
$totalrows = mysql_num_rows($result);
print "$totalrows";
?>

The test table has 20 rows, so the page should just display the number '20'. But it returns blank. The interesting thing is that this code knocks out anything else on the page and it all returns blank. Anyone see what I'm doing wrong?

croftstorm.net


Report Offensive Message For Removal

Response Number 1
Name: Laler
Date: February 9, 2007 at 10:34:08 Pacific
Subject: PHP blank page
Reply: (edit)

about the blank, maybe the server setting sets "blank" on error. Some hosting companies're doing this. Not a place for developers.

Your query is quite simple. As long as the connection is correct [ mysql_connect() or mysql_pconnect() ], the db correctly selected [ mysql_select_db() ], and the table `test` exists, it should be working.

---
Fubar


Report Offensive Follow Up For Removal

Response Number 2
Name: Michael J (by mjdamato)
Date: February 9, 2007 at 12:37:32 Pacific
Subject: PHP blank page
Reply: (edit)

A few things:

1) Eitehr you are not connecting to the database or you did not include the code in your post.

2) You should always include error handling in your database action: connecting to the database, running a query, etc. I prefer NOT to use "die" in the final production version (instead handling errors gracefully). But, there's no problem using it during development.

Based upon your code above I think the problem is definitely a problem with the query. Use this instead and report back what the error is:

<?php
$query = "SELECT * FROM test";
$result = mysql_query($query) or die (mysql_error());
$totalrows = mysql_num_rows($result);
print "$totalrows";
?>

Michael J


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: PHP blank page

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software