Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i continue this if else statement do open a alert() function in the middle of a PHP code?
    primarykey
    data
    text
    <p>I have a system to apply permit and when they select the permit they like to apply, they will submit the form and the system will check if they have any previous applied permit that is same as the pre requisites.</p> <p>In gerneral: If they do not meet the pre requisites, system should pop up a window and tell them 'Sorry, you do not have the pre-required permits'.</p> <p>Else system will check if they have completed a medical questionnaire before. If they do have an existing medical questionnaire, system will store the application details and go to the apply_successful.php page. Else System will take them to medical_questions.php to do the questionnaire.</p> <p>I tried doing the code out but was stuck at some point of it.</p> <p>I Tried this so far:</p> <pre><code>&lt;?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 '&lt;script&gt;alert("Sorry. You did have not met the Pre-Requisites for '.$permit .'");&lt;/script&gt;'; 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 '&lt;script&gt;alert("You have applied for '.$permit .'");&lt;/script&gt;'; 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); ?&gt; </code></pre> <p>I restructured the whole page and make it sond logically right. However i am not sure the way i use to echo the script out is correct.</p> <p>I wonder if anyone can comment on this code?</p> <p>Thanks so much...help is greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload