Search code examples
phpincludeanchorrequire

Go to anchor with include or require


In my index.php I have a table with data from my database. Each row has a link to edit. The edit page is a form with a submit button. When I press the submit button the data is updated in the database, and below I have

<?php
require_once 'index.php';
?>

so it seems as I go back to the index-file.

However, I would like to jump to the edited data, such as index.php#2.

<?php
require_once 'index.php#' . $ID;
?>

of course returns

Warning: require_once(index.php#2): Failed to open stream: No such file or directory in...

since there is no file called index.php#2, only index.php.

Altough if I go to index.php#2 in the browser it works as expected.

How can I jump to an anchor with include/require?

Thank you!


Solution

  • Can't be done like that. After the edit form is submitted you should redirect to the URL with an anchor tag, ie

    header('Location: /index.php#'.$ID);