我有一个申请许可证的系统,当他们选择他们想申请的许可证时,他们将提交表格,系统将检查他们是否有任何与先决条件相同的先前申请的许可证。
一般来说:如果他们不满足先决条件,系统应该会弹出一个窗口并告诉他们'对不起,您没有预先要求的许可证'。
其他系统将检查他们之前是否完成了医疗问卷。如果他们确实有一份现有的医疗问卷,系统将存储申请详细信息并转到 apply_successful.php 页面。否则系统会将他们带到 medical_questions.php 进行问卷调查。
我试着把代码写出来,但在某个时候卡住了。
到目前为止我试过这个:
<?php
session_start();
include'Connections/database.php';
$conn = dbConnect ();
if (! $conn)
die("Couldn't connect to MySQL");
$user = $_SESSION['eid'];
$selectedPermit=$_POST['cat'];
//print_r($selectedPermit);
foreach($selectedPermit as $permit)
{
$query="SELECT t.PREREQ1, t.PREREQ2, (CASE WHEN (t.PREREQ1 IS NOT NULL) AND (p1.PTYPE IS NULL) THEN 1 ELSE 0 END) AS missing1, (CASE WHEN (t.PREREQ2 IS NOT NULL) AND (p2.PTYPE IS NULL) THEN 1 ELSE 0 END) AS missing2 FROM type AS t LEFT JOIN permit AS p1 ON (t.PREREQ1=p1.ptype) AND ( p1.EID = '$user' ) AND (p1.STATUS='approved') LEFT JOIN permit AS p2 ON (t.PREREQ2=p2.ptype) AND ( p2.EID = '$user' ) AND (p2.STATUS='approved') WHERE t.PTYPE = '$permit' ";
$result=mysql_query($query,$conn);
$row=mysql_fetch_assoc($result);
$missing1=$row['missing1'];
$missing2=$row['missing2'];
if($missing1=='1' or $missing2=='1')
{
echo '<script>alert("Sorry. You did have not met the Pre-Requisites for '.$permit .'");</script>';
header ('Location:s_apply2.php');
}
}
foreach($selectedPermit as $permit)
{
$query="SELECT PTYPE FROM permit WHERE EID=$user";
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result))
{
if($row['PTYPE'] == $permit)
{
//echo"You have applied for this permit.";
echo '<script>alert("You have applied for '.$permit .'");</script>';
header ('Location:s_apply2.php');
}
}
}
foreach($selectedPermit as $permit)
{
$query="SELECT MED FROM emp WHERE EID='$user'";
$result=mysql_query($query,$conn);
$row=mysql_fetch_assoc($result);
$med=$row['MED'];
if ($med == 'yes')
{
$query = "INSERT INTO permit (EID, PTYPE) VALUES ('$user','$permit' )";
header('Location:s_apply_success.php');
}
else
{
header('Location:medical_question.php');
}
mysql_query($query);
}
dbDisconnect($conn);
?>
我重组了整个页面并使其在逻辑上正确。但是我不确定我用来回显脚本的方式是否正确。
我想知道是否有人可以评论这段代码?
非常感谢...非常感谢您的帮助。