500 Internal Server Error Given 即使代码成功完成
500 Internal Server Error Given even though code successfully completes
我有以下 PHP 脚本执行 SELECT 查询,将结果绑定到变量,根据绑定变量的值运行逻辑并对 table 取决于逻辑。此代码运行成功(我可以在我的 table 中看到相应的列已更新为正确的值)但是从服务器获取响应大约需要 10 秒,响应如下:
"The server encountered an internal error or misconfiguration and was
unable to complete your request. Please contact the server
administrator at ['private contact'] to inform them of the time this
error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error
log.
Additionally, a 500 Internal Server Error error was encountered
while trying to use an ErrorDocument to handle the request."
以下是我的脚本:
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();
感谢所有帮助,因为我不确定为什么要花这么长时间才能得到回复。
谢谢!
(编辑后的答案)在尝试通读您的代码后,缩进不正确并且阅读起来非常困难,我建议检查您的变量($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.";
}
?>
感谢您的回复。我能够确认 500 Internal Server Error 是由 4 MB 的响应大小引起的...!!!这是由逻辑的 while 循环引起的。通过删除 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();
?>
我有以下 PHP 脚本执行 SELECT 查询,将结果绑定到变量,根据绑定变量的值运行逻辑并对 table 取决于逻辑。此代码运行成功(我可以在我的 table 中看到相应的列已更新为正确的值)但是从服务器获取响应大约需要 10 秒,响应如下:
"The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at ['private contact'] to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request."
以下是我的脚本:
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();
感谢所有帮助,因为我不确定为什么要花这么长时间才能得到回复。
谢谢!
(编辑后的答案)在尝试通读您的代码后,缩进不正确并且阅读起来非常困难,我建议检查您的变量($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.";
}
?>
感谢您的回复。我能够确认 500 Internal Server Error 是由 4 MB 的响应大小引起的...!!!这是由逻辑的 while 循环引起的。通过删除 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();
?>