www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: php refresh page

  1. #1
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197

    php refresh page

    hi

    is there a php function that I can add to my code to refresh the page after it comes to the end of my script.

    thank you
    Kevin

  2. #2
    Join Date
    Mar 2005
    Location
    Guayaquil - Ecuador
    Posts
    144
    no.. if you've already sent content, you can not "refresh" the page..
    you can send some headers to change the location but just before sending any content..
    PHP Code:
    header("Location: http://your.domain.com/bla.php"); 
    But you may wanna try JavaScript to do so..
    Diego Luces

  3. #3
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859
    You could echo a refresh meta tag at the end of the script just before it exits. Like this:
    PHP Code:
    <?php
    # Your script here...
    # Your script here...
    # Your script here...

    echo('<meta http-equiv="refresh" content="20">');
    ?>
    Could that work...? I'm not exactly sure if that will work but it was just an idea that popped into my head when I read your post. I'm sorry if it doesn't work. If it does, I hope that helps.

  4. #4
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197
    no, does nothing, thank you for taking time to post
    Kevin

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,154
    First question: why do you need to refresh your page at the end of your script? (I can't think of a reason why you would, but that doesn't mean there isn't one.)
    "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

  6. #6
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197
    I have a form that deletes data from a table. The user chooses the item from the active page and presses the button. The item is deleted but they have to click a link to refresh the page.
    Kevin

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,154
    Well, it seems if you did the form processing and database update and then generated your page output, there would be no reason to refresh -- but maybe I'm missing something?
    "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

  8. #8
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197
    attached the code to give an idea what is happening. I working with the delete section

    I thought that when I get the end the delete it would reload the table but no such luck


    PHP Code:
    <?

    include 'db.php';

    $active_id $_SESSION['user_id'];

    $buddy_id $_POST['addbuddy'];

    $array explode(",",$buddy_id);

    $post_b_id $array[0];
    $first_name $array[1];
    $last_name $array[2];


    $query mysql_query("SELECT * FROM buddylink WHERE owner_id ='$active_id'") or die ("Search Error" .mysql_error());

        
    $tbl .= "<form name='dBuddy' method='post' action='addbuddy.php'>";
        
    $tbl .='<table width="200" border="1" cellspacing="2">';
          
    $tbl .='<tr>';
        
    $tbl .='<td>Delete</td>';
        
    $tbl .='<td width="303">Name:</td></tr>';

    while(
    $r=mysql_fetch_assoc($query)) {

    $f_name $r['first_name'];
    $l_name $r['last_name'];
    $b_id $r['buddy_id'];

     
     
    $tbl .= "<tr><td align=center><input type=radio name='deletebuddy' value='$b_id'></td>";
     
    $tbl .="<td><a href='SearchDetails.php?owner_id=$b_id'>$f_name $l_name</a></td></tr>";
     
    }

    $tbl .="</table>"
    $tbl .= "<input align=left type='submit' name='submit' value='Delete>";
    $tbl .= "</form>";

    if(
    $buddy_id != ""){

    // ADD TO TABLE
    $sql mysql_query("INSERT INTO buddylink (owner_id, buddy_id, first_name, last_name, added)VALUES('$active_id', '$post_b_id', '$first_name', '$last_name', now())")or die ("Link Create Error:" .mysql_error());



    }

    $d_buddy $_POST['deletebuddy'];

    if(
    $d_buddy != ""){

    mysql_query("DELETE FROM buddylink WHERE buddy_id = '$d_buddy'");

    echo 
    'Buddy has been deleted';



    }
    echo 
    $tbl;

    ?>
    Kevin

  9. #9
    Join Date
    Mar 2005
    Location
    Guayaquil - Ecuador
    Posts
    144
    you are creating the whole html output before deleting the entry.. the page wont show the updates not even when you add.. you can try this instead:

    PHP Code:
    <?

    include 'db.php';

    $active_id $_SESSION['user_id'];

    $buddy_id $_POST['addbuddy'];

    $array explode(",",$buddy_id);

    $post_b_id $array[0];
    $first_name $array[1];
    $last_name $array[2];





    if(
    $buddy_id != ""){

    // ADD TO TABLE
    $sql mysql_query("INSERT INTO buddylink (owner_id, buddy_id, first_name, last_name, added)VALUES('$active_id', '$post_b_id', '$first_name', '$last_name', now())")or die ("Link Create Error:" .mysql_error());



    }

    $d_buddy $_POST['deletebuddy'];

    if(
    $d_buddy != ""){

    mysql_query("DELETE FROM buddylink WHERE buddy_id = '$d_buddy'");

    echo 
    'Buddy has been deleted';



    }




    $query mysql_query("SELECT * FROM buddylink WHERE owner_id ='$active_id'") or die ("Search Error" .mysql_error());

        
    $tbl .= "<form name='dBuddy' method='post' action='addbuddy.php'>";
        
    $tbl .='<table width="200" border="1" cellspacing="2">';
          
    $tbl .='<tr>';
        
    $tbl .='<td>Delete</td>';
        
    $tbl .='<td width="303">Name:</td></tr>';

    while(
    $r=mysql_fetch_assoc($query)) {

    $f_name $r['first_name'];
    $l_name $r['last_name'];
    $b_id $r['buddy_id'];


    $tbl .= "<tr><td align=center><input type=radio name='deletebuddy' value='$b_id'></td>";
    $tbl .="<td><a href='SearchDetails.php?owner_id=$b_id'>$f_name $l_name</a></td></tr>";

    }

    $tbl .="</table>";
    $tbl .= "<input align=left type='submit' name='submit' value='Delete>";
    $tbl .= "</form>";

    echo 
    $tbl;

    ?>
    Hope that works..
    Diego Luces

  10. #10
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197
    thank you for the reply are fixing up my code. I figured I was doing somthing wrong

    I have been testing if user has posted by ($variable != ""){

    code .............
    }

    Is this a good way to do this or is there a better way.
    Kevin

  11. #11
    Join Date
    Mar 2005
    Location
    Guayaquil - Ecuador
    Posts
    144
    Your welcome
    And I guess you should do it this way.. [well, actually is the way I'm used to ]
    PHP Code:
    if (isset($_POST['input']) && !empty($_POST['input'])) {
     
    //add, delete or anything here..
    } else {
     
    //just output the table

    Diego Luces

  12. #12
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,154
    Just be aware that when you do a "==" or "!=" comparison or when using the empty() function; the values 0 (zero), "" (empty string) and the boolean FALSE constant are all treated as equivalent. Therefore, if zero or a boolean false is a valid entry, then you should use "===" or "!==" against an empty string when doing your comparison. Plus, I normally trim() the inputs first to get rid of leading/trailing spaces:
    PHP Code:
    foreach($_POST as $key => $val)
    {
       
    $_POST[$key] = trim($val);
    }
    if(isset(
    $_POST['input']) and $_POST['input'] !== '')
    {
      
    // good to go
    }
    else
    {
      
    // missing a required entry

    "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

  13. #13
    Join Date
    Jul 2012
    Posts
    1
    PHP Code:
    header('Location: '.$_SERVER['PHP_SELF']); 

  14. #14
    Join Date
    Jul 2012
    Posts
    5
    Quote Originally Posted by arcticwarrio View Post
    PHP Code:
    header('Location: '.$_SERVER['PHP_SELF']); 
    i use this,but inside a form.
    PHP Code:
    <form name='myform' method='post' action='".$_SERVER['PHP_SELF']."?action=del'
    but script for getting del action is above it.
    PHP Code:
    if ($_GET['action'] == "del")
    {
       
    // get the hidden value
       
    $n $_POST['n'];

       for (
    $i=0$i<=$n-1$i++)
       {
         if (isset(
    $_POST['NPM'.$i]))
         {
           
    $NPM $_POST['NPM'.$i];
           
    $query "DELETE FROM mahasiswa WHERE NPM = '$NPM'";
           
    mysql_query($query);
         }
       }

    it's didnt show you any message, but its actually refresh the page.

  15. #15
    Join Date
    Nov 2012
    Posts
    2
    Hi there!

    I have a similar problem.

    I want to delete from a table of mysql database. My problem is that after i delete a second record, only if i press 'Ctrl+F5' that record disapear.Meanwhile, from the database that record is deleted. What should i do? I have to complete that i'm working on apache server, on localhost, there was no problem.

    Thanks !

    This is the code:

    PHP Code:
    <?php
                ob_start
    ();
                        
                include 
    "conectarebd.php";
                
    $idul=$_GET['id'];
                
    mysql_query("DELETE FROM angajator WHERE id='$idul' ") or die(mysql_error());
        
                
    header('location: http://domain.ro/edit_angajator_button.php'.$random);
        
    ?>

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