第一次来这里。我正在尝试使用 PHP/HTML 表单通过数据库进行查询,然后打印找到的结果的输出。问题是,我在最后一行代码(ish)上不断收到语法错误,它从后面的行</html>
变为</body>
标签。我知道它必须是一些我想念的简单的东西,但我已经认真地看了 4 个小时并且无法弄清楚。任何帮助将不胜感激。谢谢!
这是代码:
<html>
<head>
<title>Audit Activity Report</title>
</head>
<body>
<h4>Audit Activity Report</h4>
<?php
if (!$_REQUEST['Submit']) {
html_form();
} else
{
select_cd();
}
?>
function html_form()
{
<p>Please enter the fields you would like to run a report on:</p>
<form name="Audit Activity Report" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<p>
Employee BEMS: <input name="EmployeeBEMS" type="text" size="10" maxlength="10"> </p>
<p>Escort BEMS:
<input name="EscortBEMS" type="text" size="10" maxlength="10">
</p>
<p>Current Activity ID:
<input name="CurrentActivityID" type="text" size="20" maxlength="20">
</p>
<p>
<label for="LaborTraining">LaborTraining:</label>
<select name="LaborTraining2" id="LaborTraining">
<option>Yes</option>
<option>No</option>
</select>
</p>
<p>
<label for="EthicsTraining">Ethics Training:</label>
<select name="EthicsTraining" id="EthicsTraining">
<option>Yes</option>
<option>No</option>
</select>
</p>
<p>
<label for="WorkAuthorization">Work Authorization:</label>
<select name="WorkAuthorization" id="WorkAuthorization">
<option>Yes</option>
<option>No</option>
</select>
</p>
<p>
<label for="Predicted Outcome">Predicted Outcome:</label>
<select name="Predicted Outcome" id="PredictedOutcome">
<option>Yes</option>
<option>No</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="View Report" /> </p>
<p>
<input type="reset" name="Clear" id="Clear" value="Clear" /> </p>
</form>
}
function select_cd()
{
<h4>Report</h4>
/* set's the variables for MySQL connection */
$server = "******"; // this is the server address and port
$username = "*******"; // change this to your username
$password = "*****"; // change this to your password
/* Connects to the MySQL server */
$link = mysql_connect ($server, $username, $password)
or die (mysql_error());
/* Defines the Active Database for the Connection */
if (!mysql_select_db("a32****_Audit", $link))
{
echo "<p>There has been an error. This is the error message:</p>";
echo "<p><strong>" . mysql_error() . "</strong></p>";
echo "Please Contact Your Systems Administrator with details";
}
/* Sets the SQL Query */
$sql = "SELECT * FROM Audit_Activity_Log";
$sql .= " WHERE ( Audit_Activity_Log.Employee_BEMS_ID =
'{$_POST['EmployeeBEMS']}')";
$sql2 = "SELECT * FROM Audit_Activity_Log";
$sql2 .= " WHERE ( Audit_Activity_Log.Escort_BEMS_ID =
'{$_POST['EscortBEMS']}')";
$sql3 = "SELECT * FROM Audit_Activity_Log";
$sql3 .= " WHERE ( Audit_Activity_Log.Current_Activity_ID = '{$_POST['CurrentActivityID']}')";
$sql4 = "SELECT * FROM Audit_Activity_Log";
$sql4 .= " WHERE ( Audit_Activity_Log.Labor_Training= '{$_POST['LaborTraining']}')";
$sql4 = "SELECT * FROM Audit_Activity_Log";
$sql4 .= " WHERE ( Audit_Activity_Log.Ethics_Training= '{$_POST['EthicsTraining']}')";
$sql5 = "SELECT * FROM Audit_Activity_Log";
$sql5 .= " WHERE ( Audit_Activity_Log.Work_Authorization= '{$_POST['WorkAuthorization']}')";
$sql5 = "SELECT * FROM Audit_Activity_Log";
$sql5 .= " WHERE ( Audit_Activity_Log.Predicted_Outcome= '{$_POST['PredictedOutcome']}')";
/* Passes a Query to the Active Database */
$result = mysql_query($sql, $link);
if (!$result)
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
/* Passes a Query to the Active Database */
$result2 = mysql_query($sql2, $link);
if (!$result2)
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
/* Passes a Query to the Active Database */
$result3 = mysql_query($sql3, $link);
if (!$result3)
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
/* Passes a Query to the Active Database */
$result4 = mysql_query($sql4, $link);
if (!$result4)
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
/* Passes a Query to the Active Database */
$result5 = mysql_query($sql5, $link);
if (!$result5)
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
/* Starts the table and creates headings */
echo "<table border='1'>
<tr>
<th>Employee BEMS</th>
<th> Escort BEMS</th>
<th> Current Activity ID</th>
<th> Labor Training</th>
<th>Ethics Training</th>
<th>Work Authorization</th>
<th>Predicted Outcome</th>
</tr>";
/* Retrieves the rows from the query result set
and puts them into a HTML table row */
if ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo("<tr>\n<td>" . $row["Employee_BEMS_ID"] . "</td>");
echo("<td>" . $row["Escort_BEMS_ID"] . "</td>");
echo("<td>" . $row["Current_Activity_ID"] . "</td>");
echo("<td>" . $row["Labor_Training"] . "</td>");
echo("<td>" . $row["Ethics_Training"] . "</td>");
echo("<td>" . $row["Work_Authorization"] . "</td>");
echo("<td>" . $row["Predicted_Outcome"] . "</td>\n</tr>\n\n");
}
elseif ($row = mysql_fetch_array($result2, MYSQL_ASSOC))
{
echo("<tr>\n<td>" . $row["Employee_BEMS_ID"] . "</td>");
echo("<td>" . $row["Escort_BEMS_ID"] . "</td>");
echo("<td>" . $row["Current_Activity_ID"] . "</td>");
echo("<td>" . $row["Labor_Training"] . "</td>");
echo("<td>" . $row["Ethics_Training"] . "</td>");
echo("<td>" . $row["Work_Authorization"] . "</td>");
echo("<td>" . $row["Predicted_Outcome"] . "</td>\n</tr>\n\n");
}
elseif ($row = mysql_fetch_array($result3, MYSQL_ASSOC))
{
echo("<tr>\n<td>" . $row["Employee_BEMS_ID"] . "</td>");
echo("<td>" . $row["Escort_BEMS_ID"] . "</td>");
echo("<td>" . $row["Current_Activity_ID"] . "</td>");
echo("<td>" . $row["Labor_Training"] . "</td>");
echo("<td>" . $row["Ethics_Training"] . "</td>");
echo("<td>" . $row["Work_Authorization"] . "</td>");
echo("<td>" . $row["Predicted_Outcome"] . "</td>\n</tr>\n\n");
}
elseif ($row = mysql_fetch_array($result4, MYSQL_ASSOC))
{
echo("<tr>\n<td>" . $row["Employee_BEMS_ID"] . "</td>");
echo("<td>" . $row["Escort_BEMS_ID"] . "</td>");
echo("<td>" . $row["Current_Activity_ID"] . "</td>");
echo("<td>" . $row["Labor_Training"] . "</td>");
echo("<td>" . $row["Ethics_Training"] . "</td>");
echo("<td>" . $row["Work_Authorization"] . "</td>");
echo("<td>" . $row["Predicted_Outcome"] . "</td>\n</tr>\n\n");
}
elseif ($row = mysql_fetch_array($result5, MYSQL_ASSOC))
{
echo("<tr>\n<td>" . $row["Employee_BEMS_ID"] . "</td>");
echo("<td>" . $row["Escort_BEMS_ID"] . "</td>");
echo("<td>" . $row["Current_Activity_ID"] . "</td>");
echo("<td>" . $row["Labor_Training"] . "</td>");
echo("<td>" . $row["Ethics_Training"] . "</td>");
echo("<td>" . $row["Work_Authorization"] . "</td>");
echo("<td>" . $row["Predicted_Outcome"] . "</td>\n</tr>\n\n");
}
</body>
</html>