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

时间:2019-02-25 20:07:46

标签: php html mysql mysqli wamp

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

这是我记录的错误:  [2019年2月25日星期一15:19:30.182141] [http:错误] [pid 1852:tid 1232] [客户端:: 1:57588] AH02429:响应标头名称“位置”包含无效字符,正在中止请求,引用者:{{ 3}}

这是我的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 );
}
?>

1 个答案:

答案 0 :(得分:1)

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

header("location : admin.php");

由于location和冒号之间有多余的空格,这将引发您得到的错误。更改为此(注意空格):

header("Location: admin.php");