繁体   English   中英

浏览php页面时出现内部服务器错误

[英]internal server error while navigating php pages

我正在从mysql表中获取数据并以HTML填充表。在每个表行中,我都有remove按钮,该按钮调用remove.php并从mysql表中删除该行,然后再次返回admin.php。 问题是当我单击删除按钮时,它正在执行php脚本,从数据库表中删除行。然后我再次导航到admin.php,同时浏览wamp服务器会出现500 Internal Server错误。 我想要执行删除查询,然后再次返回admin.php。 这样admin.php给了我更新的数据。 我了解发生了什么问题。

这是我记录的错误:[Mon Feb 25 15:19:30.182141 2019] [http:error] [pid 1852:tid 1232] [client :: 1:57588] AH02429:响应标头名称'location'包含无效字符,正在中止请求,引荐来源: http://localhost/project_exhibition/admin.php

这是我的admin.php

 <?php // if(isset($_SESSION["loggedin"]) && ($_SESSION["loggedin"] == true) && $_SESSION["usertype"] == a){ // } // else{ // header("location: login.php"); // exit; // } echo "<script type='text/javascript'>alert('here');</script>"; require_once "config.php"; $sql = "SELECT userid,username FROM user_login_table"; $stmt = $mysqli->prepare($sql); if($stmt->execute()) { echo "executed"; } else{ echo "not able to execute"; } $stmt->store_result(); echo $stmt->num_rows; $stmt->bind_result($id,$name); ?> <!DOCTYPE html> <html> <head> <style> table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%; } td, th { border: 1px solid #dddddd; text-align: left; padding: 8px; } tr:nth-child(even) { background-color: #dddddd; } </style> </head> <body> <h2>HTML Table</h2> <table> <tr> <th>ID</th> <th>Username</th> <th>Remove</th> </tr> <?php $rowid=0; while ($stmt->fetch()) { $rowid += 1; echo "<tr> <td>". $id." </td> <td>". $name." </td> <td> <form action='remove.php' method='post'> <input type='hidden' name ='row_id' value = ".$id." > <input type='submit' value='Remove'> </form> </td> </tr>"; } ?> </table> </body> </html> 

这是remove.php

 <?php require_once "config.php" ; echo "string"; $sql = "DELETE FROM user_login_table where userid=".$_POST['row_id'].""; $stmt = $mysqli->prepare($sql); if($stmt->execute()) { header("location : admin.php"); } else { echo "alert('Failed to Remove.Something went wrong')"; echo "failed"; } //header("location : admin.php"); ?> 

config.php文件

 <?php define('DB_SERVER','localhost'); define('DB_USER','root'); define('DB_PASSWORD',''); define('DB_NAME','exhibition_database'); $mysqli = new mysqli(DB_SERVER,DB_USER,DB_PASSWORD,DB_NAME); if($mysqli === false ) { die("Error! Couldn't connect. ". $mysqli->connect_error ); } ?> 

您的header()函数出错,您正在使用:

header("location : admin.php");

由于location和冒号之间有多余的空间,因此会抛出错误。 更改为此(注意空格):

header("Location: admin.php");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM