问题描述
在我的 index.PHP 中,我有一个包含数据库中数据的表。每行都有一个要编辑的链接。编辑页面是一个带有提交按钮的表单。当我按下提交按钮时,数据库中的数据会更新,下面是
<?PHP
require_once 'index.PHP';
?>
所以看起来我回到了索引文件。
<?PHP
require_once 'index.PHP#' . $ID;
?>
当然退货
Warning: require_once(index.PHP#2): Failed to open stream: No such file or directory in...
因为没有名为 index.PHP#2 的文件,所以只有 index.PHP。
尽管如果我在浏览器中访问 index.PHP#2,它仍会按预期工作。
如何使用 include/require 跳转到锚点?
谢谢!
解决方法
不能那样做。提交编辑表单后,您应该重定向到带有锚标记的 URL,即
header('Location: /index.php#'.$ID);