我有以下.PHP代码,其中包含HTML代码中的表格。该代码适用于事故报告,如果正确完成,应该返回用户输入。如果用户没有完成这些字段,那么代码将返回一条错误消息,并允许用户再次尝试并填写报告。在PHP代码中调用HTML代码
php代码当前编写的方式如果报告不符合要求,我可以返回错误消息,但我似乎无法在报告正确填写时返回用户输入列表。
代码:
<!DOCTYPE html>
<html lang="en">
<!---Main Content--->
<div id= "content">
<h3> Report a Wildlife Road Collison</h3>
<!---Start of php code--->
<?php
$species1 = $_POST['species'];
$species2 = $_POST['txtSpecies'];
$reportDate = $_POST['reportDate'];
$address = $_POST['address'];
$lat = $_POST['lat'];
$long = $_POST['long'];
$gender = $_POST['rbGender'];
$age = $_POST['age'];
// Checking to see if Other was selected by user. If this is true, the user input will be put in the other field.
if($species1 === "Other")
$species1 = $species2;
//checking for empty fields
if(!empty($species1)&& is_string($species1)&& !empty($location)&& is_string($location) && isset($latitude) && is_numeric($latitude) && isset($longitude) && is_numeric($longitude))
{
?> <!---end of php code--->
<!---HTML code --->
<p>Your Information has been Recorded</p>
<dl>
<dt>Species</dt>
<dd><?php print $species1; ?></dd>
<dt>Date of Incident</dt>
<dd><?php print $reportDate; ?></dd>
<dt>Address of Incident</dt>
<dd><?php print $address; ?></dd>
<dt>Latitude</dt>
<dd><?php print $lat; ?></dd>
<dt>Longitude</dt>
<dd><?php print $long; ?></dd>
<dt>Gender</dt>
<dd><?php print $gender; ?></dd>
<dt>Age</dt>
<dd><?php print $age; ?></dd>
<!---HTML code complete--->
</dl> <!---HTML code end--->
<!---Start PHP code--->
<?php
}
else{
print "<h4>Sorry</h4>";
print "<p>You didn't fill out the form completely. <a href='index.php?action=report_collision'>Try again?</a></p>";
}
?>
</div>
</html>
我试图html代码一部分分配给变量,并调用它在PHP的标签,但我不明白这是如何做正确。任何帮助,将不胜感激。
所以你总是在'else'中结束? – chris85
请将您的代码示例简化为展示您的问题的最小示例。 – k0pernikus
是的chris85,我知道我应该添加另一个if语句或者elseif? –