hi! i need to ask how refresh a page after inserting a data. i use :

print"<a href=\"update_budg.php?ras_num=$ras_num&update=1\" onClick=\"javascript: return confirm('Are you sure you want to do this?'); return;\">Update?</a>";

this link to update in other page. value is automatically insert and from "update_budg.php" , i will return to the previous page. the problem is the link is still exist although data already being insert into the database. it will dissappear after i click on the refresh button.

is there is other way for me to refresh it itself as soon as the data has been insert.

thank you

    Use Javascript as follows:

    function redirect($ras_num) { 
    echo"<script>window.location.href=\"update_budg.php?ras_num=$ras_num&update=1\"</script>";
    }
    
    // call it anywhere you want in the script with:
    
    redirect($ras_num); 
    

      If "update_budg.php" opens in a new window (with a target=\"update\" in the a tag), you can use javascript to close "update" and refresh the window that opened it:

      After update does its sql update, print this javascript to it:

      if(window.opener){
      window.opener.location.reload();
      window.close()
      }

      I use this a lot for updating, deleting, and adding to a db.

        thanks for the reply for both of you

        broc7,

        can i ask more of this pls. i've tried the code but i don't really know how to. i place it in the new window - "update_budg.php" but it doesn't work. perhaps i missplaced it or i don't specify the location it will return.

          It should work. Put a print statement in the javascript to see if the script is being run. The script doesn't need to know the opener's name or location. window.opener is enough to identify the window that opened update.

          Is update opening in a new window?

            yes it is. mmm...still doesn't work. i do use javascript

              The way I do it is, in the new window, print out standard html from the opening html tag through the opening body tag, start a php script which includes the update sql statement, and print an opening javascript tag, the javascript I posted earlier, and a closing script tag.

              All the client sees is javascript after the body tag telling it to reload the window that opened it and to close itself. If it's not working look at the new window's source and see if there's anything wrong with the javascript.

                :o i'm so sorry. i have minsunderstood your question and post a worng reply (indeed...) so sorry.

                actually it doesn't open in a new window. it open in the same window but different page.

                i'm getting blank...

                  If you want someone to click on a link and have the page refreshed to show the data changes, the best way to do it is to have the link set for the same page. Programming would determine whether anything should change in the db on each page load- whether it was loaded after a change or for the first time with no change request.

                  if($_GET["whatever"]) {
                  run some update query
                  }

                  run a select query // will get any info updated above

                  display results

                    ummm.....

                    let me understand this well. what i need to do is use $_GETS to retrieve variable. how do i send the variable using the link then?

                      You already did that with:

                      print"<a href=\"update_budg.php?ras_num=$ras_num&update=1\"

                      So you retrieve ras_num and update through $_GET[""]'s, right?

                      Instead of figuring out how to reload the first page so that it shows the updated information, set the link to the same page. The user will do the reloading for you by clicking on the link. When the page is processed by the server the second time, it would run the update query and then the select query so that the updated info is sent to the client.

                        geez~ i can't try this yet. my server's down. as i understand, post the variable with the link to the same page. use $_GET to retrieve the variable and then update the variable, finally display. can i use the same page to display or should i display at another page?

                          Write a Reply...