Page 1 of 1

PHP Code Error Causes a Blank Page

Posted: Fri Apr 10, 2009 6:42 am
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'); ?>

Re: PHP Code Error Causes a Blank Page

Posted: Fri Apr 10, 2009 7:33 am
by jaoudestudios
Turn display errors on and php will tell you what line the error is on.

Re: PHP Code Error Causes a Blank Page

Posted: Fri Apr 10, 2009 7:09 pm
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');
 

Re: PHP Code Error Causes a Blank Page

Posted: Sat Apr 11, 2009 3:23 am
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 :)

Re: PHP Code Error Causes a Blank Page

Posted: Mon Apr 13, 2009 6:39 am
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