Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Page forwarding

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Page forwarding

    Im not sure of any other way to solve my problem other than using some sort of page forwarding. I am creating a php page and i have the user submit a form... the form updates a data base and i want the page to goto my main page once the for has been submitted...

    what is the HTML or javascript code for forwarding a user to another page imediatly... No Delay

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Uhh, why not let PHP do that?
    PHP Code:
    <?php
    /*
    Handle form stuff here
    */
    header("Location: index.php"); // Or whatever page is appropriate
    ?>
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    iv tried that but i getting a error on my page that says header already set let me paste some code...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <?php
    $server		= 	"localhost";
    $user		=	"****";
    $password	=	"****";
    $dbname		=	"contest";
    $database_server = mysql_connect("$server", "$user", "$password");
    mysql_select_db("$dbname", $database_server);
    ?>
    <?
    if ($submit) {
    
             /* Maak SQL-query */
    		 $sql = "INSERT INTO Contest(Contest_ID, Description, Title, StopDate) VALUES ('', '$Description', '$Title', '$StopDate')";
    		 mysql_query($sql);
    
             header("location: http://www.cbeginnersunited.com/contestadmin.php");
    }
    ?>
    
    <head>
    <title>Add Contest - C Beginners United</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here is my error

    Warning: Cannot add header information - headers already sent by (output started at /home/domainwe/public_html/addcontest.php:3) in /home/domainwe/public_html/addcontest.php on line 18

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <?php
    $server        
    =     "localhost";
    $user        =    "****";
    $password    =    "****";
    $dbname        =    "contest";
    $database_server mysql_connect("$server""$user""$password");
    mysql_select_db("$dbname"$database_server);

    if (
    $submit) {

             
    /* Maak SQL-query */
             
    $sql "INSERT INTO Contest(Contest_ID, Description, Title, StopDate) VALUES ('', '$Description', '$Title', '$StopDate')";
             
    mysql_query($sql);

             
    header("location: [url]http://www.cbeginnersunited.com/contestadmin.php[/url]");
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Add Contest - C Beginners United</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    header() has to be sent before anything is parsed in the browser - that includes doctype declarations.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But why the DOCTYPE and HTML ? You're not displaying anything, so why add any HTML into the page at all? Taking it all out would solve the problem.

    PHP Code:
    <?php
    $server        
    =     "localhost";
    $user        =    "****";
    $password    =    "****";
    $dbname        =    "contest";
    $database_server mysql_connect("$server""$user""$password");
    mysql_select_db("$dbname"$database_server);

    if (
    $submit) {

             
    /* Maak SQL-query */
             
    $sql "INSERT INTO Contest(Contest_ID, Description, Title, StopDate) VALUES ('', '$Description', '$Title', '$StopDate')";
             
    mysql_query($sql);

             
    header("location: [url]http://www.cbeginnersunited.com/contestadmin.php[/url]");
    }

    else {
     ...
    doctype and html could go here as error message
    }
    ?>

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Oops, I should've picked up on that. Don't forget to change

    header("location: <a href="http://www.cbeginnersunited.com/contestadmin.php" target="_blank">http://www.cbeginnersunited.com/contestadmin.php</a>");

    to


    header("location: http://www.cbeginnersunited.com/contestadmin.php");


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •