SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why do i have to keep refreshing the page on UPDATE??

    Hey,

    I have the following code, where i firstly select from a datase to populate a textarea box, which is within a form. It also has an update button. Now when the update button(btn-update) is clicked i have an UPDATE statement which updates the database.

    Now the problem i have is, the UPDATE works perfectly, but i direct back to the same page upon clicking update, and the changed do not update the text box, i have to refresh the page or even navigate to another page and back to see the change..

    The update works fine but the textbox shows the changes if i reload the page, why is this?

    Heres the code:-

    PHP Code:
             <?php                 
            $dbc 
    //database connection    
            
            
    $query "SELECT content FROM tbl_homepage";
            
    $result =  mysql_query($query);
            
    $numrows mysql_num_rows($result);

            
    $row mysql_fetch_array($result,MYSQL_ASSOC);    
            
    ?>
            
            <form action="" method="post">
             <table cellspacing="5" style="margin-top:10px">
            <tr><td><h4>Steve Tappin Panel</h4></td></tr>
            <tr><td><textarea name="txt_content" style="width: 589px; height: 181px"><?php echo $row['content'?></textarea></td></tr>         
             <tr><td><input type="submit" name="btn-update" value="update details"/></td></tr>
             </table>
            </form>
            
            <?php
             
    if (isset($_POST['btn-update'])) 
                {         
                    if (
    $_POST['txt_content'] == "")
                    {    
                        echo 
    "<p>You did not complete all of the required fields.</p>";
                    }                                         
                    else 
                    {
                    
    $content mysql_real_escape_string($_POST['txt_content']);

                    
    $insert "UPDATE tbl_homepage SET content = '$content'";
                    
    $add_member mysql_query($insert);
                    
                    
    header("Location: http://www.xinfu.com/admin/manage-homepage.php");
                    }
              }
        
    ?>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your web browser is probably caching the page. You can send some http headers to advise it the page shouldn't be cached. See the documentation for header(), example #2

    I'm assuming that redirect points to the script you posted.


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
  •