我使用以下代码查询我的数据库,但页面显示为空白!
我看不出问题出在哪里!请帮忙。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Extract Student Data</title>
</head>
<body bgcolor="white">
<?php
include 'db.inc';
// Show all student data in a <table>
function displayStudentsList($connection,$query,$Year)
{
// Run the query on the DBMS
if (!($result = @ mysql_query ($query, $connection)))
showerror( );
// Find out how many rows are available
$rowsFound = @ mysql_num_rows($result);
// If the query has results ...
if ($rowsFound > 0)
{
// ... print out a header
echo "Students data Of Year $Year<br>";
// and start a <table>.
echo "\n<table>\n<tr>" .
"\n\t<th>Admission No.</th>" .
"\n\t<th>Last Name</th>" .
"\n\t<th>First Name</th>" .
"\n\t<th>Gender</th>" .
"\n\t<th>Orphan</th>" .
"\n\t<th>District</th>\n</tr>";
// Fetch each of the query rows
while ($row = @ mysql_fetch_array($result))
{
// Print one row of results
echo "\n<tr>" .
"\n\t<td>" . $row["Admission"] . "</td>" .
"\n\t<td>" . $row["last_name"] . "</td>" .
"\n\t<td>" . $row["first_name"] . "</td>" .
"\n\t<td>" . $row["Gender"] . "</td>" .
"\n\t<td>" . $row["Orphan"] . "</td>" .
"\n\t<td>" . $row["District"] . "</td>" .
"\n</tr>";
} // end while loop body
// Finish the <table>
echo "\n</table>";
} // end if $rowsFound body
// Report how many rows were found
echo "$rowsFound records found matching your
criteria<br>";
} // end of function
$scriptName = "combined.php";
// Has the user provided the parameter?
if (empty($Year))
{
// No, the user hasn't provided a parameter
?>
<form action="<?=$scriptName;?>" method="GET">
<br>Enter Year Of Admission :
<input type="text" name="Year" value="All">
(type All For All Years)
<br>
<input type="submit" value="Show Data">
</form><br>
<a href="index.html">Home</a>
<?php
} // end of if empty($Year) body
else
{
// Secure the user parameter $Year
$Year = clean($Year, 30);
// Connect to the MySQL DBMS
if (!($connection = @ mysql_connect($hostName,
$username,
$password)))
die("Could not connect");
if (!mysql_select_db($databaseName, $connection))
showerror( );
// Start a query ...
$query = "SELECT Admission,
last_name,
first_name,
Gender,
Orphan,
District
FROM osasaasasaalumni_index;"
// ... then, if the user has specified a year,
// add the Year as an AND clause ...
if ($Year != "All")
$query .= " AND year = \"$Year\"";
// ... and then complete the query.
$query .= " ORDER BY last_name";
// run the query and show the results
displayStudentsList($connection, $query, $Year);
// Close the DBMS connection
mysql_close($connection);
} // end of else if empty($Year) body
?>
</body>
</html>
我的db.inc是
<?
$hostName = "xxxxxx";
$databaseName = "xxxxx";
$username = "xxxxx";
$password = "xxxxx";
?>
代码有什么问题,因为当我调用它时,它会显示一个空白页面?
答案 0 :(得分:0)
您在本声明的最后缺少;
:
原件:
$query = "SELECT Admission,
last_name,
first_name,
Gender,
Orphan,
District
FROM osasaasasaalumni_index;"
更新:
$query = "SELECT Admission,
last_name,
first_name,
Gender,
Orphan,
District
FROM osasaasasaalumni_index;";
如果您看到空白页面且没有错误,则应启用错误报告。例如,可以在<?php
:
error_reporting(E_ALL);
ini_set('display_errors', '1');