2012-04-06 1 views
1

나는 사용자가 허가 신청을 할 수있는 시스템을 가지고 있습니다 ... 그들이 은퇴하기를 원하는 허가를 선택할 때, 시스템은 기준을 충족하는지 또는 스팸을 방지하기 위해 이전에 허가를 신청했는지를 확인할 수 있어야합니다.how와 where는 if (else) 조건을 여러 번 실행할 수 있도록 내 헤더를 배치 할 수 있습니까?

그러나 큰 문제가 있습니다. header('Location:s_success.php');을 입력하면 경고가 나타나지 않습니다. 예를 들어, 사용자가 1 또는 2 개 이상의 허가를 선택할 수 있기 때문에.

시나리오

는의가 하나 개가 신청할 수 있습니다 허가하고 아직 자격이없는 다른 허가를 선택한다고 가정 해 봅시다.

이 경우

예상 결과는 무엇을 어떻게해야 할 것은이 시스템이 성공 페이지로 직전과 동시에 그들이받을 수 없습니다 다른 허가가 성공하지 그들에게 경고해야합니다.

그러나 예기치 않은 결과 :

그들은 시스템이 바로 적용되지 허가가 성공하지 못한 사용자를 경고없이 성공 페이지로 이동합니다.

이 내 코드입니다 :

<?php 
session_start(); 
include'Connections/database.php'; 
$conn = dbConnect(); 
    if (! $conn) 
    die("Couldn't connect to MySQL"); 

    $user = $_SESSION['eid']; 
    $selectedPermit=$_POST['cat']; 
    $_SESSION['selectedPermit']=$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') 
     { 
      $message='You have not met the pre-requisites for '. $permit .' \n'; 
//    echo "You did have not met the Pre-Requisites for." .$permit; 
      echo "<script>alert(\"$message\");"; 
//    header('Location:s_apply2.php'); 
      echo "location.href='s_apply2.php';</script>"; 
     } 
     elseif($missing1 =='0' and $missing2 =='0') 
     { 
      $query="SELECT PTYPE FROM permit WHERE EID='$user'"; 
      $result=mysql_query($query); 

      if(mysql_num_rows($result)==0) 
      { 
       $query="SELECT MED FROM emp WHERE EID='$user'"; 
        $result=mysql_query($query); 
        $row=mysql_fetch_assoc($result); 
        $med=$row['MED']; 

        if($med == 'yes') 
        { 
//       echo "You are Fine."; 
         $query = "INSERT INTO permit (EID, PTYPE) VALUES ('$user','$permit')"; 
         mysql_query($query); 
         header('Location:s_apply_success.php'); 
        } 
        else 
        { 
//       echo "Go do Medical form"; 
         header('Location:medical_question.php'); 
        } 
      } 
      else 
      { 
       while($row=mysql_fetch_assoc($result)) 
       { 
        $appliedPermit[]=$row['PTYPE']; 
       } 

       if(in_array($permit,$appliedPermit)) 
       { 
         $message1='You have already applied '. $permit .' before. \n'; 
//       echo"You have already applied for ".$permit ." before <br/>"; 
         echo "<script>alert(\"$message1\");"; 
//       header('Location:s_apply2.php'); 
         echo "location.href='s_apply2.php';</script>"; 
       } 
       else 
       { 
        $query="SELECT MED FROM emp WHERE EID='$user'"; 
        $result=mysql_query($query); 
        $row=mysql_fetch_assoc($result); 
        $med=$row['MED']; 

        if($med == 'yes') 
        { 
        // echo "You are Fine."; 
         $query = "INSERT INTO permit (EID, PTYPE) VALUES ('$user','$permit')"; 
         mysql_query($query); 
         header('Location:s_apply_success.php'); 
        } 
        else 
        { 
         echo "Go do Medical form"; 
        // header('Location:medical_question.php'); 
        } 
       } 
      } 
     } 
    } 

    dbDisconnect($conn); 

?> 

의심 오류 : 내 코드에서

, 나는 header('Location:s_apply_success.php');를 사용하고 있기 때문에 발생하는 예기치 않은 결과를 유발한다는 의심. 그러나 이것이 실수인지는 확신 할 수 없습니다.

하지만 echo "You are Fine."; 대신 header('Location:s_apply_success.php');를 사용하려고 않았고 작동 : 나는 의심 오류을 디버깅 할 시도 무엇

. 그것은 에코와 팝업 신발. PHP 매뉴얼에서

+0

어떤 오류를받을 수 있나요? – Chibuzo

+0

@Chibuzo 오류는 없지만 경고가 표시되지 않고 헤더로 이동합니다. – Hubert

답변

0

:

http://php.net/manual/en/function.header.php

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

+0

흠 ... 내가 말을 끝내기 전에'header()'를 쓸 수 없다고 말하는가 ?? 그것을 읽은 후에, 내가 정확하게 해석한다면 나는 확신하지 못합니다 ... 감사합니다. – Hubert

+0

하지만 끝나기 전에 헤더를 넣지 않으면 어디에 놓아야합니까 ?? 고마워요 # – Hubert

0

표시하거나 헤더() 이전에 아무것도 표시 할 수 없습니다, 그것을 요약하면, 다음 페이지에 메시지를 전달합니다.

+0

아니요 헤더로 갈 수 있지만 경고가 나타나지 않습니다 – Hubert

0

Output bufferingheader()를 호출하기 전에 출력하여 에코를 보상합니다

<?php 
session_start(); 
ob_start(); 
include'Connections/database.php'; 
$conn = dbConnect(); 
    if (! $conn) 
    die("Couldn't connect to MySQL"); 

    $user = $_SESSION['eid']; 
    $selectedPermit=$_POST['cat']; 
    $_SESSION['selectedPermit']=$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') 
     { 
      $message='You have not met the pre-requisites for '. $permit .' \n'; 
//    echo "You did have not met the Pre-Requisites for." .$permit; 
      echo "<script>alert(\"$message\");"; 
//    header('Location:s_apply2.php'); 
      echo "location.href='s_apply2.php';</script>"; 
     } 
     elseif($missing1 =='0' and $missing2 =='0') 
     { 
      $query="SELECT PTYPE FROM permit WHERE EID='$user'"; 
      $result=mysql_query($query); 

      if(mysql_num_rows($result)==0) 
      { 
       $query="SELECT MED FROM emp WHERE EID='$user'"; 
        $result=mysql_query($query); 
        $row=mysql_fetch_assoc($result); 
        $med=$row['MED']; 

        if($med == 'yes') 
        { 
//       echo "You are Fine."; 
         $query = "INSERT INTO permit (EID, PTYPE) VALUES ('$user','$permit')"; 
         mysql_query($query); 
         header('Location:s_apply_success.php'); 
        } 
        else 
        { 
//       echo "Go do Medical form"; 
         header('Location:medical_question.php'); 
        } 
      } 
      else 
      { 
       while($row=mysql_fetch_assoc($result)) 
       { 
        $appliedPermit[]=$row['PTYPE']; 
       } 

       if(in_array($permit,$appliedPermit)) 
       { 
         $message1='You have already applied '. $permit .' before. \n'; 
//       echo"You have already applied for ".$permit ." before <br/>"; 
         echo "<script>alert(\"$message1\");"; 
//       header('Location:s_apply2.php'); 
         echo "location.href='s_apply2.php';</script>"; 
       } 
       else 
       { 
        $query="SELECT MED FROM emp WHERE EID='$user'"; 
        $result=mysql_query($query); 
        $row=mysql_fetch_assoc($result); 
        $med=$row['MED']; 

        if($med == 'yes') 
        { 
        // echo "You are Fine."; 
         $query = "INSERT INTO permit (EID, PTYPE) VALUES ('$user','$permit')"; 
         mysql_query($query); 
         header('Location:s_apply_success.php'); 
        } 
        else 
        { 
         echo "Go do Medical form"; 
        // header('Location:medical_question.php'); 
        } 
       } 
      } 
     } 
    } 

    dbDisconnect($conn); 
    ob_end_flush(); 
?> 
+0

스크립트를 사용해 보았지만 문제가 여전히 지속됩니다 – Hubert

+0

다른 방법이 있습니까? 나는 전에는 버핑하는 것을 보지 못했다 ... 너는 배우기위한 새로운 것 – Hubert

관련 문제