我有此代码,为什么我的标题位置不起作用?它是一种在我的控制面板中更新,编辑和删除某些页面的形式…并且我在form.php的同一文件夹中有一个index.php文件…任何帮助吗?()我试图将标题放在编辑和删除…并且仍然转到表单页面而不是索引…
<?php include "../../includes/site_includes.php"; //send if ((isset($_POST["send"])) && ($_POST["send"] == 1)) { $pageid = $_POST["page_id"]; $pagetitle = $_POST["page_title"]; $nameinmenu = $_POST["page_menu_name"]; $nameinurl = $_POST["page_name_url"]; $link = $_POST["page_link"]; $picture = $_POST["page_pic"]; $desc = $_POST["page_desc"]; $content = $_POST["page_content"]; } if ((isset($_POST["act"])) && ($_POST["act"] == "add")) { $sql = insertpage(); if ($result = $mysqli->prepare($sql)) { $result->bind_param("sssssss", $pagetitle, $nameinmenu, $nameinurl, $link, $picture, $desc, $content); $result->execute(); $result->store_result(); $rows = $result->num_rows; } } ////edit if ((isset($_GET["act"])) && ($_GET["act"] == "edit")) { $sql = getfrompages(); if ($result = $mysqli->prepare($sql)) { $rekza = $_GET["id"]; $result->bind_param("i", $rekza); $result->execute(); $result->store_result(); $rowsZ = $result->num_rows; } if ($rowsZ > 0) { $row = fetch($result); $pageid = $row[0]["page_id"]; $pagetitle = $row[0]["page_title"]; $nameinmenu = $row[0]["page_menu_name"]; $nameinurl = $row[0]["page_name_url"]; $link = $row[0]["page_link"]; $picture = $row[0]["page_pic"]; $desc = $row[0]["page_desc"]; $content = $row[0]["page_content"]; } } if ((isset($_GET["act"])) && ($_GET["act"] == "delete")) { $thedelid = $_GET["id"]; $sql2 = delpage(); if ($result2 = $mysqli->prepare($sql2)) { $result2->bind_param("i", $thedelid); $result2->execute(); $result2->store_result(); $rowsZ2 = $result2->num_rows; } } header('location: index.php'); exit(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> pages add </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <body> <form method="post" action=""> <table> <tr> <td style="font-weight:bold;">title</td> <td><input type="text" name="page_title" value="<?=$pagetitle?>" /></td> </tr> <tr> <td style="font-weight:bold;">name in menu</td> <td><input type="text" name="page_menu_name" value="<?=$nameinmenu?>" /></td> </tr> <tr> <td style="font-weight:bold;">name in url</td> <td><input type="text" name="page_name_url" value="<?=$nameinurl?>" /></td> </tr> <tr> <td style="font-weight:bold;">link</td> <td><input type="text" name="page_link" value="<?=$link?>" /></td> </tr> <tr> <td style="font-weight:bold;">picture</td> <td><input type="text" name="page_pic" value="<?=$picture?>" /></td> </tr> <tr> <td style="font-weight:bold;">description</td> <td><textarea name="page_desc"><?=$desc?></textarea></td> </tr> <tr> <td style="font-weight:bold;">content</td> <td><textarea name="page_content"><?=$content?></textarea></td> </tr> <tr> <td colspan="2"> <input type="hidden" name="send" value="1" /> <input type="hidden" name="act" value="<?=$_GET["act"]?>" /> <input type="hidden" name="page_id" value="<?=$pageid?>" /> <input type="submit" value="add" /></td> </tr> </table> </form> </body> </html>
解决: 使用@ Mihai Iorga代码,我添加了ob_start();
那是因为您有一个输出:
?> <?php
导致空白行输出。
在发送任何实际输出之前,必须通过常规HTML标记,文件中的空白行或从PHP中调用header()
合并所有PHP代码,并确保文件开头没有空格。
如果您还有其他脚本,也可以在header('location: index.php');添加之后exit();。
header('location: index.php');
exit();
还要将您的重定向标头移到last之后if。
if
如果有内容,那么您还可以通过注入javascript进行重定向:
<?php echo "<script>window.location.href='target.php';</script>"; exit; ?>