0

I have used this code:

$value = $_POST['searcheditem'];
header("Location : anotherpage.php?myValue=".$value);

And then inside anotherpage.php:

echo $_GET['myValue'];
// make sure to sanitize this data

But when I push any button in anotherpage.php and it refreshes the page the value of $_GET['myValue'] is lost so I get the error index 'myValue' is undefined. What can I do?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • If you refresh the page, you're sending a new request to it, without any GET or POST request variables. So, of course it will be flushed. – al'ein Oct 20 '15 at 17:10
  • You should describe why you're using that code for, what's your background. So people can actually help you with solutions or workarounds. – al'ein Oct 20 '15 at 17:11
  • If those other buttons are form submits, you need to have the form persist the value by adding it to the `action` attribute of the form. This can get painful to maintain - you might want to look into persisting the value in the user's session (i.e. via cookie) if that's appropriate for your use case – Tom Jardine-McNamara Oct 20 '15 at 17:13

0 Answers0