www.webdeveloper.com
Results 1 to 2 of 2

Thread: How do i continue this if else statement do open a alert() function in the middle of

  1. #1
    Join Date
    Nov 2008
    Posts
    8

    How do i continue this if else statement do open a alert() function in the middle of

    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.

    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'.

    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.

    I tried doing the code out but was stuck at some point of it.

    I Tried this so far:

    Code:
    <?php
    session_start();
    include'Connections/database.php';
    $conn = dbConnect ();
        if (! $conn)
        die("Couldn't connect to MySQL");
    
        $user = $_SESSION['eid'];
    
        $query="select PTYPE from permit where EID = $user";
        $result = mysql_query($query, $conn);
        $row = mysql_fetch_assoc($result);
        $permit_arr=$row['PTYPE'];
    
        foreach($permit_arr 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 ) 
                          LEFT JOIN permit AS p2 ON (t.PREREQ2=p2.ptype) AND ( p2.EID = $user ) 
                          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')
        {
    
            //I am stuck here...I would like to putan alert() here to notify user 'Sorry,you do not have the pre-required permits...and also stay on the same page which is apply2.php
        }
        else
        {
    
              $query = "select MED  from emp where EID = '$user'";
              $result = mysql_query($query, $conn);
              $row = mysql_fetch_assoc($result);
    
                  $med = $row['MED'];   
              $user =$_SESSION['eid'];
              $cat_arr=$_POST['cat'];
    
    
                  foreach ($cat_arr as $cat) 
              {
             $cat = mysql_real_escape_string($cat);
    
                       if ($med == 'yes')
                   {
                             $query = "INSERT INTO permit (EID, PTYPE) VALUES ('{$user}', '{$cat}')";
                   }
                       else
                   {
                           //do nothing
                    }
    
                        mysql_query($query);
              }
    
    dbDisconnect($conn);
    
    if ($med == 'no')
    $nextPage = "medical_question.php";
    else
    $nextPage = "s_apply_success.php";
    
    die(header("Location:{$nextPage}"));
        }
       ?>
    I am stuck at the part where I made a comment that I am stuck...which is roughly line 28.

    I wonder if anyone can guide me on how should I continue?

    Thanks so much...help is greatly appreciated.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,617
    I would probably set the desired error message in a variable, and then when you are actually generating output to the user (I'm assuming some flavor of HTML?):
    PHP Code:
    <?php if(!empty($errorMessage)) { ?>
    <script type='text/javascript'>
    alert('<?php echo $errorMessage?>')
    </script>
    <?php ?>
    Or, if you use jQuery or such, you can call one or more of its functions instead of the basic JavaScript alert() if you want to do something fancier.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles