Reputation: 311
I'm using this code ...
<?php
if (isset($_POST['submitButton'])) {
mysql_query("UPDATE notes SET Note=('$_POST[note]')
WHERE UserID='19'");
mysql_close($con);
header('Location: editrem3.htm'); //clears POST
}
?>
How do I redirect the page after the user clicks on submit and the data has been posted?
Upvotes: 4
Views: 568
Reputation: 7517
First, make sure that you are entering into the if()
condition by echo
ing something inside the if()
block.
If it's working correct, then make sure that you've sent NOTHING before the header()
is executed. Because when you use header()
in a PHP file, there MUST NOT be any other output statements before that. So, check for any HTML code or echo
s before it.
Then if you are sure that header()
is being executed, and still it's not redirecting, make sure that the target file exists.
Extra: ALWAYS add exit()
immediately after header()
redirects. Else the code will continue executing and can reveal your sensitive data.
Upvotes: 2
Reputation: 1813
use meta redirects, something like
<meta http-equiv="refresh" content="0; url=http://example.com/">
but you could do something like
<meta http-equiv="refresh" content="0; url=index.php">
works fine with me
Upvotes: 0
Reputation: 2101
Using the relative path to the file is probably causing issues. Try it using the full path (also probably outside the if{} would make more sense).
PHP might be able to parse the relative path, but the w3 spec explicitly states to use absolute URIs
edit: To elaborate, handing a relative path off to a browser for redirect is playing with fire. The browser might think it knows where it is in your site's hierarchy, but it might be actually in a different spot.
Also, if you're not getting a 404 page or something similar, then the relative path might not be your issue, but it might help you later on down the road
Upvotes: 1