updating database using a function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #1

    updating database using a function

    Is it possible to write a function that can be called up on everytime someone fills a form and submits it so that all work is done in the same page?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by anfetienne
    so that all work is done in the same page?
    how do you mean that?
    ___

    Dormi ⇐ has just set up chessidy

    Comment

    • anfetienne
      Contributor
      • Feb 2009
      • 424

      #3
      hey dorm.....i mean.....

      say i have a picture and i want to comment on it....i fill in the comment box and click on the submit button.....i dont want it to refresh the whole page, i want a function to run in the background that will post it to a DB and also refresh the connection so the last post can be seen on the page

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by anfetienne
        hey dorm
        why is everyone calling me that? it sounds like Dorm the Worm…

        say i have a picture and i want to comment on it....i fill in the comment box and click on the submit button.....i dont want it to refresh the whole page, i want a function to run in the background that will post it to a DB and also refresh the connection so the last post can be seen on the page
        what you describe is an AJAX request. but I don’t see why anyone should be disturbed by a form submit triggered page reload. (that’s what I’d expect, despite that it works even if JavaScript is disabled)

        Comment

        • anfetienne
          Contributor
          • Feb 2009
          • 424

          #5
          lol im sorry for the name, it;s just shorter to write when im rushing......

          what you say is true, but its just the case of having to reload everything on the page....didn't want it to do that but it may be the best option

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            whatever you do (AJAX or not), it’s your choice. eventually, the code behind is nearly the same.

            Comment

            • anfetienne
              Contributor
              • Feb 2009
              • 424

              #7
              ok thanks for the advice

              Comment

              • anfetienne
                Contributor
                • Feb 2009
                • 424

                #8
                ok i managed to find a very very good ajax tutorial to do this and I am working with the code now with ease... the tut made it real simple...

                but now i have one question? How can I update this ajax code so once it has processed through the php and is successful it displays the submitted text back on the page? I have a feeling this will probably be moved to the ajax section but I have posted here because the part I'm pulling my hair out is including php

                Code:
                   1. $.ajax({  
                   2.   type: "POST",  
                   3.   url: "bin/process.php",  
                   4.   data: dataString,  
                   5.   success: function() {  
                   6.     //display message back to user here  
                   7.   }  
                   8. });  
                   9. return false;

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  I guess that’s what the success method should do.

                  Comment

                  • anfetienne
                    Contributor
                    • Feb 2009
                    • 424

                    #10
                    i know how to add a success method that can change from one div layer to another but I can't seem to work out how to get it to include the entry just placed in a DB

                    Comment

                    Working...