Forum Moderators: coopster
I got a form page with 'update' & 'cancel' buttons. When 'cancel' clicked, I want to be redirected to the index page on the right page number.
URL of my edit page is like this:
[localhost...]
In the form.php I got few lines of code to get that 'cursor' before doing redirection:
$iCursor = $_GET["cursor"];
$url = 'index.php?cursor='.(int) $iCursor;
if ($_POST["cancel"]) {
header("Location: $url");
}
The new URL is supposed to be:
[localhost...]
but it showed up like this:
[localhost...]
I've tried using sessions variables as well, but the value of the cursor's still 0.
Do you guys know what happened?
Cheers,
$iCursor = $_GET["cursor"];
$url = "index.php?cursor=$iCursor";
Second, debug the url. Comment the header() line and print the url. If it gets printed with cursor=0 you know for sure that the problem is in the code above.
if ($_POST["cancel"]) {
//header("Location: $url");
echo "The url is '$url'";
}
For example, it could be that $_GET["cursor"] isn't 2 but something else, empty for example. Actually, this might be it: $_GET["cursor"] for some reason is the empty string and (int) of the empty string is 0.
Hanu has a good tip here, but I wouldn't even wait to get into the "if" logic statement, dump the value immediately and troubleshoot from there.
$iCursor = $_GET["cursor"];
$url = 'index.php?cursor='.(int) $iCursor;
exit [php.net]("The url is '$url'");
$iCursor = 2;
the header can pass the value on, but not if
$iCursor = $_GET["cursor"];
I also echoed $iCursor and the value is there, but it will have been empty when redirected to another page.
Things to check:
- Try interpolation as I suggested in my earlier post and tell us what happens.
- What's your PHP version? Before 4.1.0 you needed to use $HTTP_GET_VARS instead of $_GET.
- Examine $_GET["cursor"] closely. Is it really set? Use
phpinfo( INFO_VARIABLES );
to dump the value of all get, post, cookie and server variables.
- $_GET is an associative array (hash). The key lookup with hashes is case sensitive. $_GET["CURSOR"] is different to $_GET["cursor"] which is different to $_GET["Cursor"].
HTH