I keep getting an error 404 telling me that the pages at location1 and 2 are missing but they are created and saved in the same folder. Can someone tell me what i am doing wrong. Currnet page is editpage.php and i want to redirect to the others depending on what is clicked.

<?php
if ($url) {
   header("Location: $url");
   exit;
   }
$location1="bobs.html";
$location2="addrecord.php";
?>
<html>
<body bgcolor="#6699FF">
 <form method=Post Action="editpage.php"><?php echo "<input name=\"url\" Type=\"hidden\" value=\"location1\">";?><input type="submit" value="Update Lectures" ></form>
<form method=Post Action="editpage.php"><?php echo "<input name=\"url\" Type=\"hidden\" value=\"location2\">";?><input type="submit" value="Add to Lectures"></form>
</body>
</html>

    You are defining the url AFTER you send the header.

      1) Yep, the variable definitions will have to go before they are used.
      2) You can't just call a variable by sending another variable. The closest thing I can think of is naming a variable by using $$.
      You're looking for a switch.

        Try just going echo and displaying$url.
        Also try using $
        POST and isset i.e.

        if(isset($POST["url"]))_{

        __header("Location:".$_POST["url"]);

        ___exit;

        ___}

          Ok i did what you said press711 using isset and $_Post. I dont get error 404 anymore instead the page just stays the same and does not go to any of the locations. Any other suggestion, please remember i am just new to this.

            <?php
            if (isset($POST["url"])) {
            header("Location: ".$
            POST["url"]);
            exit;
            }
            $location1="bobs.html";
            $location2="addrecord.php";
            ?>
            <html>
            <body bgcolor="#6699FF">
            <form method=Post Action="editpage.php"><?php echo "<input name=\"url\" Type=\"hidden\" value=\"".$location1."\">";?><input type="submit" value="Update Lectures" ></form>
            <form method=Post Action="editpage.php"><?php echo "<input name=\"url\" Type=\"hidden\" value=\"".$location2."\">";?><input type="submit" value="Add to Lectures"></form>
            </body>
            </html>

            I have tested the code and it works.
            Firstly,
            $url might not work properly becuase POST variables are stored as $POST[..], if ou have register_globals (i.e. global variables) in your code on it will transfer all $GET[..] , $_POST[..] etc to their corresponding variable as you were using above. But uding register_globals is a security risk and bad programming technique and should be avoided.

            The isset fucntion will simply check if the value of the variable has been set.

            Now after yesterday's changes which you made from my suggestions it was now redirecting you to a file whose name is stored in $POST["url"]. At the moment it was storing the string "location1" not the value of the variable $location1. So I simply changed the code to print the value of variable $location1 and $location2 in the code. Now $post["url"] was directily storing the filenames. And that does the trick.

            For more on :
            isset : http://www.php.net/isset
            $_post : http://www.freewebmasterhelp.com/tutorials/php/6
            register_globals and variable scope : http://www.zend.com/manual/language.variables.scope.php

            Let me know if you need help understanding something.

              Write a Reply...