PHP code bringin back blank page
Posted: Fri Feb 06, 2009 4:43 pm
Hi I'm having trouble with some php code that I have been writing for my final year project at university and was wondering if any could have look...
The code is quite simply meant to open a database I have created on my local machine and build a table using HTML with its values. I'm using Xampp to check everything works but when I open this php file through my browser it just brings back a blank page.
The code:
<?php
//connect to the database
$mysqli = mysqli_connect("localhost", "my_username", "my_password", "my_database");
$content = "<h1>Antrim</h1>";
//check if the database has any records
$sql = 'SELECT branch.name, salesperson.salesman_no, salesperson.first_name, salesperson.last_name, hhc.hhc_asset_no, single_dock.single_d_asset_no, printer.printer_asset_no'
. ' FROM branch'
. ' LEFT JOIN ('
. ' salesperson, hhc, single_dock, printer'
. ' ) ON ( salesperson.branch_no = branch.branch_no'
. ' AND hhc.salesman_no = salesperson.salesman_no'
. ' AND single_dock.salesman_no = salesperson.salesman_no'
. ' AND printer.salesman_no = salesperson.salesman_no ) '
. ' WHERE salesperson.branch_no =001 LIMIT 0, 30 ';
$check_branch_res = mysqli_query($mysqli, $sql)
or die(mysqli_error($mysqli));
if (mysqli_num_rows($check_branch_res) < 1)
{
$content = "<p>There are no entries at this branch</p>";
}
else
{
$content = "
<table cellpadding=\"3\" cellspacing=\"2\" border=\"1\" width=\98%\">
<tr>
<th>Branch</th>
<th>Salesman No.</th>
<th>First Name</th>
<th>Last Name</th>
<th>HHC Asset No.</th>
<th>Single Dock Asset No.</th>
<th>Printer Asset No.</th>
</tr>";
while ($branch_info = mysqli_fetch_array($check_branch_res))
{
$bname = $branch_info['name'];
$id = $branch_info['salesman_no'];
$fname = $branch_info['first_name'];
$lname = $branch_info['last_name'];
$hhc_an = $branch_info['hhc_asset_no'];
$sdock_an = $branch_info['single_d_asset_no'];
$printer_an = $branch_info['printer_asset_no'];
$content = "
<tr>
<td align=\"center\">$bname<br></td>
<td align=\"center\">$id<br></td>
<td align=\"center\">$fname<br></td>
<td align=\"center\">$lname<br></td>
<td align=\"center\">$hhc_an<br></td>
<td align=\"center\">$sdock_an<br></td>
<td align=\"center\">$printer_an<br></td>
</tr>";
}
$content = "</table>";
}
?>
<html>
<head>
<title>Antrim Equipment List</title>
<link rel=StyleSheet href="main.css" type="text/css" media=all>
</head>
<body>
<?php echo $content;?> //this may be where the problem is happening
</body>
</html>
I think there may be a problem when the browser hits this line I've highlighted. The variable $content may not be saving the HTML code but I have no idea why. I'm sure it's something really simple but I just can't figure it.
Thanks for any help,
Jamie
The code is quite simply meant to open a database I have created on my local machine and build a table using HTML with its values. I'm using Xampp to check everything works but when I open this php file through my browser it just brings back a blank page.
The code:
<?php
//connect to the database
$mysqli = mysqli_connect("localhost", "my_username", "my_password", "my_database");
$content = "<h1>Antrim</h1>";
//check if the database has any records
$sql = 'SELECT branch.name, salesperson.salesman_no, salesperson.first_name, salesperson.last_name, hhc.hhc_asset_no, single_dock.single_d_asset_no, printer.printer_asset_no'
. ' FROM branch'
. ' LEFT JOIN ('
. ' salesperson, hhc, single_dock, printer'
. ' ) ON ( salesperson.branch_no = branch.branch_no'
. ' AND hhc.salesman_no = salesperson.salesman_no'
. ' AND single_dock.salesman_no = salesperson.salesman_no'
. ' AND printer.salesman_no = salesperson.salesman_no ) '
. ' WHERE salesperson.branch_no =001 LIMIT 0, 30 ';
$check_branch_res = mysqli_query($mysqli, $sql)
or die(mysqli_error($mysqli));
if (mysqli_num_rows($check_branch_res) < 1)
{
$content = "<p>There are no entries at this branch</p>";
}
else
{
$content = "
<table cellpadding=\"3\" cellspacing=\"2\" border=\"1\" width=\98%\">
<tr>
<th>Branch</th>
<th>Salesman No.</th>
<th>First Name</th>
<th>Last Name</th>
<th>HHC Asset No.</th>
<th>Single Dock Asset No.</th>
<th>Printer Asset No.</th>
</tr>";
while ($branch_info = mysqli_fetch_array($check_branch_res))
{
$bname = $branch_info['name'];
$id = $branch_info['salesman_no'];
$fname = $branch_info['first_name'];
$lname = $branch_info['last_name'];
$hhc_an = $branch_info['hhc_asset_no'];
$sdock_an = $branch_info['single_d_asset_no'];
$printer_an = $branch_info['printer_asset_no'];
$content = "
<tr>
<td align=\"center\">$bname<br></td>
<td align=\"center\">$id<br></td>
<td align=\"center\">$fname<br></td>
<td align=\"center\">$lname<br></td>
<td align=\"center\">$hhc_an<br></td>
<td align=\"center\">$sdock_an<br></td>
<td align=\"center\">$printer_an<br></td>
</tr>";
}
$content = "</table>";
}
?>
<html>
<head>
<title>Antrim Equipment List</title>
<link rel=StyleSheet href="main.css" type="text/css" media=all>
</head>
<body>
<?php echo $content;?> //this may be where the problem is happening
</body>
</html>
I think there may be a problem when the browser hits this line I've highlighted. The variable $content may not be saving the HTML code but I have no idea why. I'm sure it's something really simple but I just can't figure it.
Thanks for any help,
Jamie