www.webdeveloper.com
Results 1 to 4 of 4

Thread: Display updated MySQL

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    4

    Display updated MySQL

    I have a form on one page that sends information to a PHP script for processing. Once processed, this information is updated in the database and the page redirects back to the form page where the updated results are supposed to display. The PHP does exactly what it's supposed to do, but the updated results are not displayed on the redirect. If I refresh the form page, the updated results display correctly so I assumed that the redirect was happening too soon and added a three second javascript delay before the redirect. That didn't work. I did usleep in my PHP between updated the database and the redirect still inconsistent. Following is the PHP that I'm using. Suggestions??

    Code:
    $query="delete from `messages` where `messageid` = '$record'";
    $result=$db->query($query);
    
    /// I've tried adding usleep(3000) here as well
    
    $query="select * from `messages` where `to` = '".$_SESSION['profileid']."'";
    $result=$db->query($query);
    $_SESSION['messagecount']=$result->num_rows; /// This is the number that should refresh on redirect
    
    echo '
    Deleting messages ...
    <script>
    setTimeout(function() {
    window.location="'.$_SESSION['pagefrom'].'?id='.$_SESSION['lastviewed'].'&purge=true";
    },3000);
    </script>';
    Thanks in advance.
    sleepydad

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,537
    I'm guessing that on the redirect the form is using the latest cached copy of the page, then when you refresh it the browser actually requests a fresh copy from the server. You could try setting some no-caching headers on the main page and see if that helps.

    (My personal preference is to avoid redirects in the first place, instead using a single page approach (e.g. a single controller such as used in most MVC frameworks).)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2010
    Posts
    4
    Hi NogDog -

    Thanks for the reply. Where do I put these in my script? I put them in the <head></head> tags, and got the error messages that headers have already been sent.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,537
    It would need to be done before anything actually gets output to the browser (including anything not within <?php ... ?> tags). So it might be something like:
    PHP Code:
    <?php
    header
    ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    ?>
    <!DOCTYPE html>
    <html>
    ...
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles