Hey everyone! I encountered an error in this particular piece of code, below is the error message. All my other website's code works fine except doEditAccount.php.
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at postmaster@localhost to let them know when the error occurred and what you did before the error occurred.
More information about this error may be available in the server error log.
Apache/2.4.54 (Win64) OpenSSL/1.1.1p PHP/8.2.0 server is located on localhost port 80.
以下是我的代码:Account.php:
//User can choose to edit or delete their account here session_start(); include_once("linkConnection.php"); include_once("navbar.php"); include_once("session.php"); if(isset($_SESSION['userId'])){ $userId=$_SESSION['userId']; $query="SELECT * FROM users WHERE userId = $userId"; $Result=mysqli_fetch_assoc(mysqli_query($link,$query)); echo "
Username : ".$_SESSION['username']; echo "
Password : ".$Result['password']; echo "
Name : ".$Result['name']; echo "
Date of Birth : " .$Result['dob']; echo "
Email : " .$Result['email']; ?>
Current Level : (You need more points to level up!)
Account.php form input will be passed to doEditAccount.php, below is the code.
error_reporting(E_ALL); ini_set('display_errors', '1'); include_once("linkConnection.php"); include_once("navbar.php"); include_once("session.php"); if(isset($_POST['edit1'])){ }else{ } // $_SESSION['Cmsg'] = Customization Message if (isset($_POST['edit2'])) { if (isset($_POST['color'])) { $plaincolor = $_POST['color']; setcookie("lv5BG", "", time() - 3600); // Remove lv5BG cookie if it exists setcookie("lv10BG", "", time() - 3600); // Remove lv10BG cookie if it exists setcookie("plaincolor", $plaincolor, time() 60 * 60 * 24 * 365 * 10); $_SESSION['Cmsg'] = "You have successfully changed background to $plaincolor."; } elseif (isset($_POST['lv5BG'])) { $lv5BG = $_POST['lv5BG']; setcookie("plaincolor", "", time() - 3600); // Remove plaincolor cookie if it exists setcookie("lv10BG", "", time() - 3600); // Remove lv10BG cookie if it exists setcookie("lv5BG", $lv5BG, time() 60 * 60 * 24 * 365 * 10); $_SESSION['Cmsg'] = "You have successfully changed background to $lv5BG."; } elseif (isset($_POST['lv10BG'])) { $lv10BG = $_POST['lv10BG']; setcookie("plaincolor", "", time() - 3600); // Remove plaincolor cookie if it exists setcookie("lv5BG", "", time() - 3600); // Remove lv5BG cookie if it exists setcookie("lv10BG", $lv10BG, time() 60 * 60 * 24 * 365 * 10); $_SESSION['msg'] = "You have successfully changed background to $lv10BG."; } else { $_SESSION['Cmsg'] = "You have submitted nothing. No change to customizations."; } header('Location : Login.php'); } ?>
Login.php:
TODO supply a title
然后我重定向到Login.php,让用户看到他们更新的背景。问题是,当我点击“确认更改”按钮时,它给我显示之前在doEditAccount.php网站上提到的错误,除此之外,我的其他网站都能正常工作。有什么问题的想法吗?
我以为是重定向的问题,所以尝试删除header("Location:Login.php"),但问题仍然存在。这个网站以前是正常工作的,突然间当我再次运行它时,它就出现了这个错误,无法解决。
Try to remove the space after Location in header('Location: Login.php');, change it to header('Location: Login.php');, and add an exit statement under the header function to prevent Executing any further code after sending the redirect header is considered good practice when using header() for redirects.
like this: