0

ここで最初のタイマー。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>
4

3 に答える 3

0

私は他の答えに同意します。PHP の開始タグと終了タグがありません。

<?php ?>

デバッグするもう 1 つの良い方法は、Apache を使用している場合、Apache error_log です。何度かお世話になりました。

于 2013-05-01T04:22:39.353 に答える
0

PHP の開始タグと終了タグがありません -

function html_form()
{

やれ -

<?php

function html_form()
{

HTMLこれらのメソッドを認識していないphp場合は、コードの前半で行った方法と同じようにしてください。

ロジック部分をビューと分離する必要があります。以下に示す方法のようにします(他の方法も多数あります)。

<?php

//PHP code chunks

?>
HTML Part
<?php

//Another PHP code chunks

?>
Again your HTML part
于 2013-05-01T04:08:25.553 に答える