Hi,

I can't seem to figure out why the header function is not working in this conditional loop. Everything inside of it is executing just fine except for that stupid little header().

Here is my code, I start it off with the call to the function.

<?PHP
/*
This is how I'm calling the function.
*/
echo  "<a href=\"adminPanel.php?do=menus&action=mUP&mID={$menu['menu_name']}&mPOS={$menu['menu_position']}&mODR={$menu['menu_order']}\"><img src=\"images/up.gif\" border=\"0\"></a>&nbsp;"
     ."<a href=\"adminPanel.php?do=menus&action=mDN&mID={$menu['menu_name']}&mPOS={$menu['menu_position']}&mODR={$menu['menu_order']}\"><img src=\"images/down.gif\" border=\"0\"></a>&nbsp;";



/*
Function I'm using to order elements.  I don't think it's super important but I wanted to include it incase someone spots a screwup.
*/
function modify_menus() {
  global $tblBGColor1, $tblBGColor2, $tblBGColor3;
  $action = $_GET['action'];
  db_conn();
  $getMenus = mySQL_QUERY ("SELECT * FROM menus ORDER BY menu_position ASC");
  $numMenus = mySQL_NUM_ROWS($getMenus);
  display_menus($ttl='yes', $mPosition='left');
  display_menus($ttl='no', $mPosition='right');
  if ($action == 'mUP') {
    $menu_name     = $_GET['mID'];
    $menu_position = $_GET['mPOS'];
    $menu_order    = $_GET['mODR'];

$getREPLACEMENT = mySQL_QUERY ("SELECT menu_name, menu_position, menu_order
                                  FROM menus
                                    WHERE menu_order = ($menu_order - 1)
                                      AND menu_position LIKE '$menu_position'");;

while ($replacement = mySQL_FETCH_ARRAY ($getREPLACEMENT)) {
  $repName = $replacement['menu_name'];
  $repPosition = $replacement['menu_position'];
  $repOrder = $replacement['menu_order'];
}

mySQL_QUERY ("UPDATE menus
                SET menu_order = '$repOrder'
                  WHERE menu_name = '$menu_name'");

mySQL_QUERY ("UPDATE menus
                SET menu_order = '$menu_order'
                  WHERE menu_name = '$repName'");

header ("Location: adminPanel.php?do=menus");
  }
  if ($action == 'mDN') {
    $menu_name     = $_GET['mID'];
    $menu_position = $_GET['mPOS'];
    $menu_order    = $_GET['mODR'];

$getREPLACEMENT = mySQL_QUERY ("SELECT menu_name, menu_position, menu_order
                                  FROM menus
                                    WHERE menu_order = ($menu_order + 1)
                                      AND menu_position LIKE '$menu_position'");;

while ($replacement = mySQL_FETCH_ARRAY ($getREPLACEMENT)) {
  $repName = $replacement['menu_name'];
  $repPosition = $replacement['menu_position'];
  $repOrder = $replacement['menu_order'];
}

mySQL_QUERY ("UPDATE menus
                SET menu_order = '$repOrder'
                  WHERE menu_name = '$menu_name'");

mySQL_QUERY ("UPDATE menus
                 SET menu_order = '$menu_order'
                   WHERE menu_name = '$repName'");
  }
}
?>

Any suggestions would be great. Thx.

    Thats an easy one - your header isn't at the head 🙂

    Your headers must be the first thing passed to the browser.

    You have echo'ed some stuff before your headers are sent.

      Yeah, I thought that too but there is noting being output to the browser.

      There is that and I am only doing a re-direction and I'm not setting the header to a certain content type.

      I set my error reporting to E_ALL but I'm not getting anything back which I find disturbing. I don't think the header() function is being looked at at all. Hmmm....

        The "echo" statement, at the top of the script, is "output". You can use output buffering to solve your problem.

          The echo statement is being output inside of another function. I didn't think it was a problem because I have that working all over the place (guess it might not be right but it works).

          If I were to use output buffering here, how would I go about doing so in this particular case (i.e. the redirect)?

            Hi,

            check if the script or any script included by that script contains any empty lines outside PHP blocks. That's output, too. Remove any empty lines or e.g. HTML code outside PHP blocks.

            Thomas

              Thx for your help everyone but it's still not working. I've been working this out in my head.

              This document holds all of the functions for a particular module. I stripped out ALL of the HTML/output and only put the header() funciton inside of the conditionals. Nothing.

              To me, it looks like the conditions are being met so...I took out the header() and threw in a quick echo 'text'; string in there and it output just fine under the conditions.

              The include path. This particular document is being included in another page but it does not include other documents. SO, I'm kind of wondering where the problem is. I thought about it some more and I figured instead of re-writing the whole thing line by line and satisfying my curiosity, I am going to cheat and put a stupid little JS redirect after my php code runs. I know, I know but hey, it works.

              I appreciate the help on this one. Stupid non parsing header() funciton!

                Write a Reply...