删除有效,页面重定向但删除后的网址为http://localhost:/manage_items.php?yesdelete=23
为什么会这样?它应该是manage_items.php
while ($row = $get_products->fetch()) {
$item_id = $row['item_id'];
$user_id = $row['user_id'];
$item_name = $row['item_name'];
$date = $row['add_date'];
$image = $row['photopath'];
$products .= "<br/><img src = $image><img> Item ID: $item_id UserID: $user_id NAME:
$item_name Added on: $date  
<a href='item_edit.php?pid=$item_id'>Edit</a> 
<a href='manage_items.php?deleted=$item_id'>Delete</a>";
}
//delete Item
if(isset($_GET['deleted'])) {
echo 'delete this product?'.$_GET['deleted'].'<a
href="manage_items.php?yesdelete='.$_GET['deleted'].'">Yes<a/>
/ <a href ="manage_items.php">No</a>';
exit();
}
if(isset($_GET['yesdelete'])) {
$deleteid = $_GET['yesdelete'];
$sql = $db->exec("DELETE FROM item WHERE `item_id` = '$deleteid' LIMIT 1");
$image_delete = 'file_to/$deleteid';
if(file_exists($image_delete)) {
unlink($image_delete);
}
header("Location: manage_items.php");
exit();
}
答案 0 :(得分:0)
标题,即使我没有看到整个代码我看到你输出的空白字符串:
?>
<?php
删除所有这些地方以及可以完成输出的其他地方 - 然后重定向将起作用
另外,我真的建议你使用正确的重定向:
function redirect($url)
{
if (!headers_sent())
{
if (strtoupper($_SERVER['SERVER_PROTOCOL']) == 'HTTP/1.1')
@header('HTTP/1.1 303 See Other', true, 303);
else
@header('HTTP/1.0 302 Found', true, 302);
@header('Location: ' . $url);
@header('Content-type: text/html');
}
echo '<html><head><title>Redirect</title><meta http-equiv="Refresh" content="0;URL='.htmlspecialchars($url).'"></head><body>'.
'<a href="'.htmlspecialchars($url).'">Click here</a>'.
'</body></html>';
@ob_flush();
exit();
}
答案 1 :(得分:0)
看起来已经发送了一个标题的情况。
您必须执行以下操作。
删除代码块。
?>
<?php
在第一个<?
?>
或至少确保之后没有空格或换行符。编辑:您还在重定向之前发送html。在这里,我重新安排了您的代码。我已将删除块移到了开头。
<?php
//delete Item
if(isset($_GET['yesdelete']))
{
$deleteid = $_GET['yesdelete'];
$sql = $db->exec("DELETE FROM item WHERE `item_id` = '$deleteid' LIMIT 1");
$image_delete = 'file_to/$deleteid';
if(file_exists($image_delete))
{
unlink($image_delete);
}
header("Location: manage_items.php");
exit();
}
while ($row = $get_products->fetch())
{
$item_id = $row['item_id'];
$user_id = $row['user_id'];
$item_name = $row['item_name'];
$date = $row['add_date'];
$image = $row['photopath'];
$products .= "<br/><img src = $image><img> Item ID: $item_id UserID: $user_id NAME:
$item_name Added on: $date  
<a href='item_edit.php?pid=$item_id'>Edit</a> 
<a href='manage_items.php?deleted=$item_id'>Delete</a>";
}
if(isset($_GET['deleted']))
{
echo 'delete this product?'.$_GET['deleted'].'<a
href="manage_items.php?yesdelete='.$_GET['deleted'].'">Yes<a/>
/ <a href ="manage_items.php">No</a>';
exit();
}
?>
答案 2 :(得分:0)
这就是问题所在。它位于我页面顶部的会话块中
session_start();
if(!isset($_SESSION['id']))
{
header("Location: yackimo_register_form.php");
exit();
}
$userID = $_SESSION['id'];
echo "";<<<------------
坏习惯