SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2006
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I redirect before inserting data?

    At the moment I'm adding a record to mysql and using header() to redirect the user.

    Would it be better if I put the header() command before the insert statement or won't that make any difference? i.e. can the user be redirected without having to wait for the insert to complete?

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    One way or another, the insert has to be done so personally I would do the insert and then redirect.

    JMHO

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    generally, if some part of my script needs to be executed, i do it first before i tell the browser to go elsewhere.

    if you really need to make sure part of your script is executed, you can also look at ignore_user_abort()

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2006
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies. It's actually more important that the user get's redirected than the database is updated on this occasion.

    Just wondered if it actually made a difference if one statement was before the other.

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2006
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone know if it makes a difference to the order?

  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2005
    Posts
    485
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Code.Warrior
    Anyone know if it makes a difference to the order?
    unless your insert is MASSIVE, the difference will be negligible. as in imperceptible. try it and see if it is ok.

    you could redirect to another page and then process the insert, but it will require sessions and increase the complexity of your code.

  7. #7
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sending the header does not stop the script from finishing it's execution. A header is a browser instruction. You can put them either way.

    Edit:

    But whether or not the browser requests the new page before your script has finished, is another matter.


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
  •