gpt4 book ai didi

php - 即使代码成功完成,仍给出 500 内部服务器错误

转载 作者:行者123 更新时间:2023-11-29 10:49:02 25 4
gpt4 key购买 nike

我有以下 PHP 脚本,它执行 SELECT 查询、将结果绑定(bind)到变量、根据绑定(bind)变量的值运行逻辑,并根据逻辑对表执行另一个更新。此代码成功运行(我可以看到表中相应的列已更新为正确的值),但需要大约 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();

感谢所有帮助,因为我不确定为什么需要这么长时间才能得到回复。

谢谢!

最佳答案

感谢您的回复。我能够确认 500 内部服务器错误是由 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 - 即使代码成功完成,仍给出 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44075075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com