-2

I am trying to make it so when the page reloads it redirects me with the same $_GET parameters as the previous page. Right now I am trying to use header to achieve this, but when I submit my form the variable $id is blank.

HTML Form

<form action = "." method ="post">
<input type = "text" name = "username">
<textarea name = "comments"></textarea>
<input type = "hidden" name = "action" value = "posts"> 
<input type = "submit" name = "submit" value = "Add Post">
</form>

Redirect Script

if ( empty( $_GET ) && !empty($_POST) ){
if($action == 'posts'){
if(!isset($_GET['thread'])){
$id = $_GET['thread'];
header('Location: ' . $_SERVER['REQUEST_URI'] .'?thread='.$id);
}   
}

Thanks for anyone who replies!

1 Answers1

0

Your redirect script doesn't make a lot of sense. Try this, maybe

if ( empty( $_GET ) && !empty($_POST) ){
    if(isset($_POST['thread'])){
        $id = $_POST['thread'];
        header('Location: ' . $_SERVER['REQUEST_URI'] .'?thread='.$id);
    }   
}
Chris Lear
  • 6,592
  • 1
  • 18
  • 26