SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    looking for auto forwarding function

    Hi,

    I am looking for a function in php that will automatically forward a user to another page. It is a form submit page and after the data has been submitted I want to go directly to another page which I define in the script. How can I do that?
    I just cant figure out how to use the php.net manual. Hence I am looking for help here.

    Thanks in advance.

  2. #2
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is header() what you want?

    example:
    header ("Location: http://www.php.net");

  3. #3
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think theres something wrong. Heres what I get on executing the script.

    PHP Code:
    WarningCannot add header information headers already sent by (output started at templates\header.inc:3in c:\apache\htdocs\surplusgemstones\admin\productedit.php on line 47 
    I think this is because I have already defined a header before in the document. And no, I cant put the statement in the header file since that header is shared by lot of other pages.

    What I want to do exactly is:

    Theres a page called edit.php where the user fills out a form.
    On clicking submit another page called productedit.php is trigger which run an update query to the database.

    What I want is that after the product has been updated the user should be taken to the product_desp.php automatically.

    thus I want the productedit.php file to do something like this:
    PHP Code:
    if ($sql ) {
        echo(
    "<P>Product updated</P>");
        
    //forward to the product_desp.php page   } 
    else {
        echo(
    "<P>Error updating product: " .
             
    mysql_error() . "</P>");
      } 
    I hope I have been able to explain what I want.
    Any help would be appreciated.
    Thanks

  4. #4
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah.. unfortunately, if your page is outputting any html prior to the header() call, it'll fail. You could try doing this with javascript:

    PHP Code:
    <?
    if ($sql ) {
    ?>
    <P>Product updated</P>
    <A HREF="product_desp.php">View the Update</A>
    <script language="javascript">
    <!--
    document.location="product_desp";
    // --></script>
    <?

    else {
        echo(
    "<P>Error updating product: " mysql_error() . "</P>");
    }
    ?>
    This way, if the user has javascript enabled, the page will automatically be forwarded.. if not, the link to the next page will show up for the user to click on.

  5. #5
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try putting ob_start() before the output is sent, and then ob_end_flush() after you write the headers.

    http://www.zend.com/manual/ref.outcontrol.php

  6. #6
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres what I did

    PHP Code:
     if ($sql ) {
        echo("<P>Product updated</P>");
        echo("<A HREF='product_desp.php'?$ids>View the Update</A>");

    ?>
    <script language="javascript">
    document.location="product_desp"?<?=$ids?>;</script>
    <?
      
    } else {
        echo(
    "<P>Error updating product: " .
             
    mysql_error() . "</P>");
      }
    But the browser returns the following javascript error.

    Line:21
    Character: 38
    Error: Expected ':'
    Code: 0

    Heres the line 21 of the output html

    HREF='product_desp.php'?id=1>View the Update</A><script

    Heres the html output code little before and after the line

    <A HREF='product_desp.php'?id=1>View the Update</A><script language="javascript">
    document.location="product_desp"?id=1;</script>

    I am not good at javascript. So please help.

    Thanks for the help.

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change

    PHP Code:
    <script language="javascript">
    document.location="product_desp"?<?=$ids?>;</script>
    to

    PHP Code:
    <script language="javascript">
    document.location="product_desp.php?<?=$ids?>";</script>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Zealot NZ Joe's Avatar
    Join Date
    Apr 2001
    Location
    Kapiti, New Zealand
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got around a similar problem using a meta-refresh
    < META HTTP-EQUIV=Refresh CONTENT="2; URL=http://your-url/" >
    Last edited by Hierophant; Jul 6, 2001 at 07:30.
    Gravity always wins

  9. #9
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <META HTTP-EQUIV=Refresh CONTENT="2; URL=http://your-url/">
    Kevin


Bookmarks

Posting Permissions

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