2017-05-19 5 views
0

SELECT 쿼리를 수행하고 결과를 변수에 바인딩하고 바인딩 된 변수의 값을 기반으로 논리를 실행하고 해당 변수에 따라 다른 UPDATE를 수행하는 다음 PHP 스크립트가 있습니다. 논리. 이 코드는 성공적으로 실행되며 (테이블에서 올바른 값으로 업데이트 된 해당 열을 볼 수 있음) 서버에서 응답을 되 찾는 데 약 10 초가 소요되며 응답은 다음과 같습니다.500 코드가 성공적으로 완료되었지만 내부 서버 오류가 발생했습니다

"서버 내부 오류 또는 구성 오류가 발생하여 요청을 완료 할 수 없습니다. 관리자에게 [ '개인 연락처']에 문의하여 오류가 발생한 시간과이 오류가 발생하기 직전에 수행 한 작업을 알려주십시오. 이 오류에 대한 자세한 내용은 서버 오류로그에서 사용할 수 있습니다.

또한 요청을 처리하기 위해 ErrorDocument를 사용하려고 시도하는 중에 012 내부 서버 오류 오류 이 발생했습니다. " 모든 도움은이 응답을 너무 오래 걸리는 이유는 확실하지 않다으로 감사

include("../../include/session.php"); 

include('inc.php'); 

if ((isset($_POST['lotnumberinput'])) AND (isset($_POST['sgref']))) { 


$sgref = $_POST['sgref']; 
$lotnumber = $_POST['lotnumberinput']; 

$conn = new mysqli($servername, $username, $password, $dbname); 

    if ($conn->connect_errno) { 
     echo "There was a problem connecting to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error; 
    } 

    if (!($sqlget = $conn->prepare("SELECT lotnumber, lotnumber2, lotnumber3 FROM invoicesJan2016 WHERE id = ?"))) { 
     echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
    } 

    if (!$sqlget->bind_param("s", $sgref)) { 
     echo "Binding parameters failed: (" . $sqlget->errno . ") " . $sqlget->error; 
    } 

    if (!$sqlget->execute()) { 
     echo "Execute failed: (" . $sqlget->errno . ") " . $sqlget->error; 
    } 


    $sqlget->bind_result($lotnumber1, $lotnumber2, $lotnumber3); 

    $res = $sqlget->fetch(); 

    $sqlget->free_result(); 

if ($res) { 

    while ($res) { 


     if ($lotnumber1 == "") { 


      if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber = ? WHERE id = ?"))) { 
       echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
      } 

      if (!$sql->bind_param("ss", $lotnumber, $sgref)) { 
       echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error; 
      } 


      if (!$sql->execute()) { 
        echo "Execute failed: (" . $sql->errno . ") " . $sql->error; 

      } else { 

       echo "SG Successfully Added!"; 
      } 


     } else if (($lotnumber1 !== "") AND ($lotnumber2 == "")) { 


      if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber2 = ? WHERE id = ?"))) { 
       echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
      } 


      if (!$sql->bind_param("ss", $lotnumber, $sgref)) { 
       echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error; 
      } 


      if (!$sql->execute()) { 
        echo "Execute failed: (" . $sql->errno . ") " . $sql->error; 

      } else { 

       echo "SG Successfully Added!"; 
      } 


     } else if (($lotnumber1 !== "") AND ($lotnumber2 !== "") AND ($lotnumber3 == "")) { 


      if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber3 = ? WHERE id = ?"))) { 
       echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
      } 


      if (!$sql->bind_param("ss", $lotnumber, $sgref)) { 
       echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error; 
      } 


      if (!$sql->execute()) { 
        echo "Execute failed: (" . $sql->errno . ") " . $sql->error; 

      } else { 

       echo "SG Successfully Added!"; 
      } 


     } else { 

      echo "There are too many lot numbers associated with this SG. Please call IT to request additional space."; 

     } 

    } // End While. 

}//end if 


} else { 

    echo "SG Number did not save. Please try again."; 

} 

$sqlget->close(); 
$sql->close(); 
$conn->close(); 

:

다음

내 스크립트입니다.

감사합니다.

+0

는 당신은 오류보고 기능을 사용할 수 있습니까? 로그 파일에서 뭔가가 있는지 확인할 수 있습니까? –

+0

들여 쓰기가 끔찍하고 도움을주기 위해 코드를 읽는 것이 정말 힘들어지기 때문에 사실 그것은 다운 voted입니다. 다만을 위해, 그것은 나의 투표가 아니었다. – Alfabravo

+0

@alfabravo .... 좋아, 나는 그것을 명심 할 것이다. 제안 해 주셔서 감사합니다. 질문의 실제 주제와 관련하여 오류 로그는 500 개의 내부 오류가 응답 제한에 대한 Mod Security 규칙에 의해 발생하며 응답이 mod 규칙에 비해 너무 큽니다. 나는 현재이 문제에 대해 더 자세히 조사 중이다. – rdimouro

답변

1

감사합니다. 500MB 내부 서버 오류가 4MB의 응답 크기 때문에 발생했음을 확인할 수있었습니다 ... !!! 이것은 로직의 while 루프로 인해 발생했습니다. 그 동안 페이지를 제거하고 로직 구성 요소를 재구성하면 응답이 상당히 작아지고 완벽하게 작동합니다. 다음은 정상적으로 작동하는 코드의 업데이트 된 버전입니다. 도와 주신 모든 분들께 감사드립니다 !!! 내 코드는

:

<?php 

include("../../include/session.php"); 
include('inc.php'); 

if ((isset($_POST['lotnumberinput'])) AND (isset($_POST['sgref']))) { 

    $sgref = $_POST['sgref']; 
    $lotnumber = $_POST['lotnumberinput']; 

    $conn = new mysqli($servername, $username, $password, $dbname); 

    if ($conn->connect_errno) { 
     echo "There was a problem connecting to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error; 
    } 

    if (!($sqlget = $conn->prepare("SELECT lotnumber, lotnumber2, lotnumber3 FROM invoicesJan2016 WHERE id = ?"))) { 
     echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
    } 

    if (!$sqlget->bind_param("s", $sgref)) { 
     echo "Binding parameters failed: (" . $sqlget->errno . ") " . $sqlget->error; 
    } 

    if (!$sqlget->execute()) { 
    echo "Execute failed: (" . $sqlget->errno . ") " . $sqlget->error; 
    } 

    $sqlget->bind_result($lotnumber1, $lotnumber2, $lotnumber3); 

    $res = $sqlget->fetch(); 

    $sqlget->free_result(); 

    if ($res) { 

    if ($lotnumber1 == "") { 

     if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber = ? WHERE id = ?"))) { 
     echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
     } 

    } else if (($lotnumber1 !== "") AND ($lotnumber2 == "")) { 

     if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber2 = ? WHERE id = ?"))) { 
     echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
     } 

    } else if (($lotnumber1 !== "") AND ($lotnumber2 !== "") AND ($lotnumber3 == "")) { 

     if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber3 = ? WHERE id = ?"))) { 
     echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
     } 

    } else { 

     $sql = ""; 

    } 

    if (!($sql == "")) { 

     if (!$sql->bind_param("ss", $lotnumber, $sgref)) { 

     echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error; 
     } 

     if (!$sql->execute()) { 

     echo "Execute failed: (" . $sql->errno . ") " . $sql->error; 

     } else { 

     echo "SG Successfully Added!"; 
     } 

    } else { 

     echo "There are too many lot numbers associated with this SG. Please call IT to request additional space."; 

    } 

    }//end if 

} else { 

    echo "SG Number did not save. Please try again."; 

} 

$sqlget->close(); 
$sql->close(); 
$conn->close(); 

?> 
0

코드를 제대로 들여 쓰기되지 을 읽으려고 후 (편집 답) 정말 어려운 읽기하게, 나는 당신의 변수 ($sqlget, $sql, $conn)는 여전히의 인스턴스를 보유 여부를 확인하는 것이 좋습니다 것 수업을 통해 실제로 무엇이든 닫을 수 있습니다.

<?php 

include("../../include/session.php"); 

include('inc.php'); 

if ((isset($_POST['lotnumberinput'])) AND (isset($_POST['sgref']))) { 

    $sgref = $_POST['sgref']; 
    $lotnumber = $_POST['lotnumberinput']; 
    $conn = new mysqli($servername, $username, $password, $dbname); 

    if ($conn->connect_errno) { 
     echo "There was a problem connecting to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error; 
    } 

    if (!($sqlget = $conn->prepare("SELECT lotnumber, lotnumber2, lotnumber3 FROM invoicesJan2016 WHERE id = ?"))) { 
     echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
    } 

    if (!$sqlget->bind_param("s", $sgref)) { 
     echo "Binding parameters failed: (" . $sqlget->errno . ") " . $sqlget->error; 
    } 

    if (!$sqlget->execute()) { 
     echo "Execute failed: (" . $sqlget->errno . ") " . $sqlget->error; 
    } 

    $sqlget->bind_result($lotnumber1, $lotnumber2, $lotnumber3); 
    $res = $sqlget->fetch(); 
    $sqlget->free_result(); 

    if ($res) { 

     while ($res) { 

      if ($lotnumber1 == "") { 

       if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber = ? WHERE id = ?"))) { 
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
       } 

       if (!$sql->bind_param("ss", $lotnumber, $sgref)) { 
        echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error; 
       } 

       if (!$sql->execute()) { 
        echo "Execute failed: (" . $sql->errno . ") " . $sql->error; 
       } else { 
        echo "SG Successfully Added!"; 
       } 

      } else if (($lotnumber1 !== "") AND ($lotnumber2 == "")) { 

       if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber2 = ? WHERE id = ?"))) { 
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
       } 

       if (!$sql->bind_param("ss", $lotnumber, $sgref)) { 
        echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error; 
       } 

       if (!$sql->execute()) { 
        echo "Execute failed: (" . $sql->errno . ") " . $sql->error; 
       } else { 
        echo "SG Successfully Added!"; 
       } 

      } else if (($lotnumber1 !== "") AND ($lotnumber2 !== "") AND ($lotnumber3 == "")) { 

       if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber3 = ? WHERE id = ?"))) { 
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; 
       } 

       if (!$sql->bind_param("ss", $lotnumber, $sgref)) { 
        echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error; 
       } 

       if (!$sql->execute()) { 
        echo "Execute failed: (" . $sql->errno . ") " . $sql->error; 
       } else { 
        echo "SG Successfully Added!"; 
       } 

      } else { 
       echo "There are too many lot numbers associated with this SG. Please call IT to request additional space."; 
      } 

     } // End While. 

    }//end if 

    if($sqlget != null){$sqlget->close();} 
    if($sql != null){$sql->close();} 
    if($conn != null) {$conn->close();} 

} else { 
    echo "SG Number did not save. Please try again."; 
} 

?> 
+0

if 로직 외부에서 스크립트의 가까운 부분을 이동 시켰고 동작은 동일합니다 ... – rdimouro