PHP Code Error Causes a Blank Page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pauldr
Forum Newbie
Posts: 18
Joined: Fri Apr 10, 2009 6:40 am

PHP Code Error Causes a Blank Page

Post by pauldr »

I am new to PHP and MySQL, I'm trying to create a page that displays a SELECT statement inside of a table. When I run the page, it goes blank. I've reviewed the code and looked at examples online. I'm not sure what I am missing. I'm confident that the error is the php code displaying the data in the table. Can anyone guide me as to the problem?

-------------CODE-------------------------
<html>

<!-- Header -->
<? include("../include/header.php"); ?>

<!-- Menu -->
<? include('../include/menu.php'); ?>

<div id='main'>
<!-- Begin Content -->

<?php
<!-- Database Connection -->
require('../include/connect.php');

$result = mysql_query('
SELECT
category.name,
item.short_desc,
item.part_no,
item.vendor,
item.unit_price,
item.long_desc,
item.max_qty
FROM
item, category
WHERE
item.deleted = 1 AND item.category_id = category.id
ORDER BY
item.id DESC');

}
echo '<table border="1">
<tr>
<th>Category</th>
<th>Short Description</th>
<th>Part No</th>
<th>Vendor</th>
<th>Unit Price</th>
<th>Description</th>
<th>Max Qty</th>
<th></th>
<th></th>
<th></th>
</tr>';

while($row = mysql_fetch_assoc($result))
{
echo '<tr bgcolor=$bgcolor>';
echo '<td>' . $row['category.name'] . "</td>";
echo '<td>' . $row['item.short_desc'] . "</td>";
echo '<td>' . $row['item.part_no'] . "</td>";
echo '<td>' . $row['item.vendor'] . "</td>";
echo '<td>' . $row['item.unit_price'] . "</td>";
echo '<td>' . $row['item.long_desc'] . "</td>";
echo '<td>' . $row['item.max_qty'] . '</td>';
echo '<td> <a href="">Update</a> </td>';
echo '<td> <a href="">Delete</a> </td>';
echo '<td> <a href="">Order</a></td>';
echo '<tr>';
}

echo '</table>';
?>
<!-- End Content -->

<!-- Footer -->
<? include('../footer.php'); ?><html>

<!-- Header -->
<? include("../include/header.php"); ?>

<!-- Menu -->
<? include('../include/menu.php'); ?>

<div id='main'>
<!-- Begin Content -->

<?php
<!-- Database Connection -->
require('../include/connect.php');

$result = mysql_query('
SELECT
category.name,
item.short_desc,
item.part_no,
item.vendor,
item.unit_price,
item.long_desc,
item.max_qty
FROM
item, category
WHERE
item.deleted = 1 AND item.category_id = category.id
ORDER BY
item.id DESC');

}
echo '<table border="1">
<tr>
<th>Category</th>
<th>Short Description</th>
<th>Part No</th>
<th>Vendor</th>
<th>Unit Price</th>
<th>Description</th>
<th>Max Qty</th>
<th></th>
<th></th>
<th></th>
</tr>';

while($row = mysql_fetch_assoc($result))
{
echo '<tr bgcolor=$bgcolor>';
echo '<td>' . $row['category.name'] . "</td>";
echo '<td>' . $row['item.short_desc'] . "</td>";
echo '<td>' . $row['item.part_no'] . "</td>";
echo '<td>' . $row['item.vendor'] . "</td>";
echo '<td>' . $row['item.unit_price'] . "</td>";
echo '<td>' . $row['item.long_desc'] . "</td>";
echo '<td>' . $row['item.max_qty'] . '</td>';
echo '<td> <a href="">Update</a> </td>';
echo '<td> <a href="">Delete</a> </td>';
echo '<td> <a href="">Order</a></td>';
echo '<tr>';
}

echo '</table>';
?>
<!-- End Content -->

<!-- Footer -->
<? include('../footer.php'); ?>
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP Code Error Causes a Blank Page

Post by jaoudestudios »

Turn display errors on and php will tell you what line the error is on.
nyoka
Forum Commoner
Posts: 45
Joined: Thu Apr 09, 2009 12:53 pm

Re: PHP Code Error Causes a Blank Page

Post by nyoka »

Personally I always use the following two lines of code to force errors to be displayed.

Code: Select all

 
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', '1');
 
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP Code Error Causes a Blank Page

Post by jaoudestudios »

McInfo wrote:

Code: Select all

My preference for debugging is
[code=php]error_reporting(E_ALL);
I agree, show everything, even notices. Just because php is forgiving does not mean we should write bad code. A real programmer declares everything so will have no notices :)
pauldr
Forum Newbie
Posts: 18
Joined: Fri Apr 10, 2009 6:40 am

Re: PHP Code Error Causes a Blank Page

Post by pauldr »

Thank you to everyone, I was able to identify the errors and move to the next step by changing the php.ini file to display all errors.

Paul
Post Reply