导航 php 个页面时出现内部服务器错误
internal server error while navigating php pages
我正在从 mysql table 中获取数据并在 HTML 中填充 table 。在每个 table 行中,我删除了调用 remove.php 并将该行从 mysql table 中删除,然后再次 return 到 admin.php。
问题是,当我单击删除按钮时,它正在执行 php 脚本,从 database.Then 中的 table 中删除行,我正在再次导航到 admin.php
导航 wamp 服务器时会出现 500 Internal Server 错误。
我想要的是执行删除查询,然后再次 return 到 admin.php。这样 admin.php 就会给我更新的数据。我知道出了什么问题。
这是我记录的错误:
[2 月 25 日星期一 15:19:30.182141 2019] [http:error] [pid 1852:tid 1232] [client ::1:57588] AH02429:响应 header 名称 '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
和冒号之间的额外 space,这将引发您遇到的错误。将其更改为此(注意 space):
header("Location: admin.php");
我正在从 mysql table 中获取数据并在 HTML 中填充 table 。在每个 table 行中,我删除了调用 remove.php 并将该行从 mysql table 中删除,然后再次 return 到 admin.php。 问题是,当我单击删除按钮时,它正在执行 php 脚本,从 database.Then 中的 table 中删除行,我正在再次导航到 admin.php 导航 wamp 服务器时会出现 500 Internal Server 错误。 我想要的是执行删除查询,然后再次 return 到 admin.php。这样 admin.php 就会给我更新的数据。我知道出了什么问题。
这是我记录的错误: [2 月 25 日星期一 15:19:30.182141 2019] [http:error] [pid 1852:tid 1232] [client ::1:57588] AH02429:响应 header 名称 '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
和冒号之间的额外 space,这将引发您遇到的错误。将其更改为此(注意 space):
header("Location: admin.php");