The code says "Internal Server Error" and doesn't redirect me to the correct website.
P粉819533564
P粉819533564 2023-07-27 09:52:09
0
1
379
<p>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. </p><p>Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. </p><p>Please contact the server administrator at postmaster@localhost to let them know when the error occurred and what you did before the error occurred. </p><p>More information about this error may be available in the server error log. </p><p>Apache/2.4.54 (Win64) OpenSSL/1.1.1p PHP/8.2.0 server is located on localhost port 80.</p><p>以下是我的代码:Account.php:</p><p><br /></p> <pre class="brush:php;toolbar:false;">//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 " <br><b>Username</b> : ".$_SESSION['username']; echo "<br><b>Password</b> : ".$Result['password']; echo "<br><b>Name</b> : ".$Result['name']; echo "<br><b>Date of Birth</b> : " .$Result['dob']; echo "<br><b>Email</b> : " .$Result['email']; ?> <form action="editAccount.php" method="post"> <input type="submit" value="Edit Account" name="edit1"/> </form> <br> <form action="deleteAccount.php" method="post"> <input type="submit" value="Delete Account"/> </form> <br><br> <?php } else{ echo "Please Login to View Account Information."; } ?> <html> <head> </head> <body> <h3>Account Customization</h3> <?php $Points_needed=100-$Result['points']; ?> <p>Current Level : <?php echo $Result['level']?> (You need <?php echo $Points_needed?> more points to level up!)</p> <div class="w3-light-grey"> <div id="myBar" class="w3-container w3-green w3-center" style="width:<?php echo $Result['points']?>%"><?php echo $Result['points']?></div> </div> <?php if (isset($_SESSION['userId'])){?> <form action="doEditAccount.php" method="post"> <br/><br/> <div class="level-container"> <label>Level 1 :</label> <br> <br> <input type="radio" name="color" value="lightgrey" />Light Grey <input type="radio" name="color" value="lightyellow"/>Light Yellow <input type="radio" name="color" value="beige"/>Beige <input type="radio" name="color" value="lightpink"/>Light Pink <input type="radio" name="color" value="darkseagreen"/>Dark Sea Green <input type="radio" name="color" value="lightblue"/>Light Blue </div> <?php ?> <?php if ($Result['level']>=5){ ?> <div class="level-container"> <label>Level 5 :</label> <br> <br> <input type="radio" name="lv5BG" value="background.jpg" />Mystical Background <input type="radio" name="lv5BG" value="hellokitty.jpg" />Hello Kitty Background <input type="radio" name="lv5BG" value="yellow.jpg" />Flowery Background </div> <?php }else{ ?> <div class="level-container"> <label>Level 5 :</label> <br> <br> <input type="radio" name="lv5BG" value="background.jpg" disabled/>Mystical Background <input type="radio" name="lv5BG" value="hellokitty.jpg" disabled/>Hello Kitty Background <input type="radio" name="lv5BG" value="yellow.jpg" disabled/>Flowery Background </div> <?php } if ($Result['level']>=10){?> <div class="level-container"> <label>Level 10 :</label> <br><br> <input type="radio" name="lv10BG" value="lv10 - movable rainbow.gif" />Movable rainbow gif <input type="radio" name="lv10BG" value="lv10 - lightbugs.gif" />Mystical Movable Firebugs </div> <?php }else{?> <div class="level-container"> <label>Level 10 :</label> <br><br> <input type="radio" name="lv10BG" value="lv10 - movable rainbow.gif" disabled/>Movable rainbow gif <input type="radio" name="lv10BG" value="lv10 - lightbugs.gif" disabled/>Mystical Movable Firebugs </div> <?php } ?> <input type="submit" value="Confirm Change" name="edit2"/> </form> <?php } ?> </body> </html></pre> <p>Account.php form input will be passed to doEditAccount.php, below is the code.</p> <pre class="brush:php;toolbar:false;">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'); } ?></pre> <p>Login.php:</p> <pre class="brush:php;toolbar:false;"><?php session_start(); include_once("navbar.php"); include_once("session.php"); $backgroundStyle = ""; if (isset($_COOKIE['plaincolor'])) { $backgroundStyle = "background-color: " . $_COOKIE['plaincolor'] . ";"; } elseif (isset($_COOKIE['lv5BG'])) { $backgroundStyle = "background-image: url(images/".$_COOKIE['lv5BG'].")"; }elseif (isset($_COOKIE['lv10BG'])) { $backgroundStyle = "background-image: url(images/".$_COOKIE['lv10BG'].")"; echo $_COOKIE['lv10BG']; }echo $backgroundStyle; ?> <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body style="<?php echo $backgroundStyle?>; background-size: cover; background-repeat: no-repeat;"> <!-- form --> <?php if (isset($_SESSION['msg'])){ ?> <div class="alert alert-success"> <h5><?php echo $_SESSION['msg'];?></h5> </div> <?php } unset($_SESSION['msg']); ?> <form name="Login" method="post" action="doLogin.php" class="ReviewEdit"> <h1>Login Page :</h1> <?php if(isset($_COOKIE['username'])){?> Your Username: <br> <input style="border:2px solid black;" id="idName" type="text" name="Uname" placeholder="Enter your username" value="<?php echo $_COOKIE['username']?>"/> <br><br> <?php }else{?> Your Username: <br> <input style="border:2px solid black;" id="idName" type="text" name="Uname" placeholder="Enter your username" /> <?php } ?> Your Password: <br> <input style="border:2px solid black;" id="idEmail" type="password" name="pw" placeholder="Enter your password"/> <br><br> <input type="checkbox" value="Remember me" name="Remember">Remember Me <a href="forget-password.php">Forget Password</a> <input type="submit" value="Login"> <br><br> </form> <h5 class="notImportant forlogin"> Not a member yet? Register <a href="Register.php" style="color: darkslategray">here</a> </h5> </body> </html></pre> <p>然后我重定向到Login.php,让用户看到他们更新的背景。问题是,当我点击“确认更改”按钮时,它给我显示之前在doEditAccount.php网站上提到的错误,除此之外,我的其他网站都能正常工作。有什么问题的想法吗?</p><p>我以为是重定向的问题,所以尝试删除header("Location:Login.php"),但问题仍然存在。这个网站以前是正常工作的,突然间当我再次运行它时,它就出现了这个错误,无法解决。</p><p><br /></p>
P粉819533564
P粉819533564

reply all(1)
P粉994092873

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:


header('Location: Login.php');
exit;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!