Since I'm starting with PHP, I just can't figure out why this sequence does not work. It brings me a clean page with nothing in it.
I ran the script with echo on the "POST[uid']" and "POST['edupdel']" and both are received from the calling script.
All scripts
PHP Code:
<?php
ob_start();
session_start();
if (isset($_POST['uid']))
{
$uid = $_POST['uid'];
}
else
{
die("UID NOT FOUND");
}
if (!isset($_POST['edupdel']))
{
die("Edupdel not found");
}
else
{
$opt = $_POST['edupdel'];
}
if ($opt == "listone")
{
header('Location:selectone_user.php?uid=$uid');
exit;
}
if ($opt == "noselect")
{
header("Location:invalid_option.php");
exit;
}
if ($opt == "update")
{
header("Location:update_user.php");
exit;
}
if ($opt == "listall")
{
header("Location:listall_user.php");
exit;
}
if ($opt == "delete")
{
header("Location:delete_user.php");
exit;
}
if ($opt == "add")
{
header("Location:add_user.php");
exit;
}
ob_end_flush();
?>
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
ob_start();
session_start();
if (isset($_POST['uid']))
{
$uid = $_POST['uid'];
}
// ...etc....
if ($opt == "add")
{
header("Location:add_user.php");
exit;
}
ob_end_flush();
echo "<p>DEBUG: Should we have gotten here?</p>";
?>
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Thank You for the help. In the last minutes before leaving work I found the answer:
PHP Code:
if ($opt == "add") { echo "<script> window.location.href='add_user.php?uid=$uid'</script>"; }
Note that since I'm working on localhost I do not need at this point the .. www...
Nevertheless your example will be used as a guide when I go into production.
Now, independently of my approach, I would really appreciate if you could lead me to the way where your example would work for me. I think that solving the issue the way I did does not make the one that is not working go away. I'd like to have both options. So, if you are up to it, with some infinite patience, it would interesting to find out why the Header("Location: does not work for me.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
This line reminds me of General Relativity and Quantum Mechanics when taken looking at Black Holes for the quantum perspective. The answers do not fit the way the World seems to work.
Sorry, I digress...
Going back to what is important. Thank You for your help. I tested your example and it would only show me the dreaded white (blank page). Not even the last echo shows up.
Anyway, even though I solved the issue using a bit of Javascript :
PHP Code:
if ($opt == "add") { echo "<script> window.location.href=add_user.php?uid=$uid'</script>";
exit; }
Now, independently of my approach, I would really appreciate if you could lead me to the way where your example would work for me. I think that solving the issue the way I did does not make the one that is not working go away. I'd like to have both options. So, if you are up to it, with some infinite patience, it would interesting to find out why the Header("Location: does not work for me.
If you get a blank page, first do a "view source" just in case something was returned but is interpreted by the browser as being all mark-up with no content.
Otherwise, if it's truly blank, that is usually a parse/compile error. When that happens, if your web server's PHP configuration has display_errors turned off, then nothing will be displayed. Therefore, in your development environment, it's useful to turn it on; or else put a tail on your php-errors.log file to see if it tells you what happened. (It's also useful to use a code editor that auto-detects parse errors, to at least let you find those before you actually try running it.)
However, my editor did not detect any parse errors when I copy/pasted your original code. It's possible it's "working" up to the point where the browser receives the Location HTTP header, but is unable to process it. I don't think it's required, but I always include a space after the "Location:". Also, if testing locally, you can still use a full URL:
PHP Code:
header("Location: http://localhost/file.php");
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks