WEB executing php code within itself?

Discussion in 'OT Technology' started by BoostedBoogie, May 29, 2008.

  1. so lately i've been trying to mix some javascript with my php more often. what i'm doing is when you click on a form button, a seperate div (first set to display:none) will pop up which has a transparent black over the entire layout and has a "database updated" or some sort of loading bar on top. it's the exact same thing you would see in light box, then when loading is complete, there is a link which hides the div again.

    the problem i'm having is that the form action is sent directly to a seperate php file to do all of the database updating, so you only see the loading bar for a split second before it goes to the blank php file.

    what i'm trying to figure out is how to set up an if statement so that once the form button is pressed, it'll just execute that same exact code in the same file rather than an external file? i know it's something as simple as using if(isset['execute'] and having the button name/id as execute? or am i thinking totally underestimating this method?
     
  2. Josh

    Josh Guest

    It sounds like you should just use AJAX to post the data to the server
     
  3. i would, but this was a feature that was a last-minute thing that i'm implementing into an already-existing project which is due in about a week. i know ajax is the perfect way to go for this but don't have enough time to put it together.
     
  4. Kevin

    Kevin New Member

    Joined:
    Aug 27, 2002
    Messages:
    87,634
    Likes Received:
    0
    Location:
    Michigan
    I'm confused. Why can't you post to the same page again?
     
  5. Kevin

    Kevin New Member

    Joined:
    Aug 27, 2002
    Messages:
    87,634
    Likes Received:
    0
    Location:
    Michigan
    in .net, you would use page.ispostback
     
  6. JoeyJoJoJuniorShabadoo

    JoeyJoJoJuniorShabadoo Live Free or Die

    Joined:
    Nov 9, 2004
    Messages:
    4,347
    Likes Received:
    0
    Location:
    http://www.stogietime.com
    well you can't really do that using php unless you use ajax
     
  7. JoeyJoJoJuniorShabadoo

    JoeyJoJoJuniorShabadoo Live Free or Die

    Joined:
    Nov 9, 2004
    Messages:
    4,347
    Likes Received:
    0
    Location:
    http://www.stogietime.com
    or i have no idea how you would do it
     
  8. Josh

    Josh Guest

    Ajax really would take 5 minutes to implement. Check out the php example on w3schools.
     
  9. JoeyJoJoJuniorShabadoo

    JoeyJoJoJuniorShabadoo Live Free or Die

    Joined:
    Nov 9, 2004
    Messages:
    4,347
    Likes Received:
    0
    Location:
    http://www.stogietime.com
    :werd: I did some ajax stuff and it was pretty easy.
     
  10. so all of the databasing and php would be done within the ajax script? any quick tutorials around? couldn't find anything specific to updating a database
     
  11. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    no, you'd have the same external php script update the database, just call it with AJAX instead of using the form post.
     
  12. intrktevo

    intrktevo New Member

    Joined:
    Oct 18, 2004
    Messages:
    5,781
    Likes Received:
    0
    Location:
    UCF
    look at a javascript framework to use ajax quickly..i like www.jquery.com
     
  13. any source code examples in using ajax to call my php file in the background? :dunno:

    i spent a few hours trying different methods, calling functions to hide and show my divs, etc to no avail. i guess it simply isn't possible to mix this javascript concept with php w/o having to use ajax :hs:
     
  14. ok so i've tried out the code on there...the effect works perfectly now, but it's saying that the xmlHttp isn't defined...should i be setting the xmlHttp variable to something?
     
  15. 96

    96 Merry Christmas :D

    Joined:
    Oct 30, 2001
    Messages:
    16,073
    Likes Received:
    0
    Location:
    San Diego
    using jQuery would make this about 2 lines :)
     
  16. i actually figured it out over the weekend. i just had the form action echo $PHP_SELF and had my code inside set to an if(isset(whatever)) and before the code does anything at all, i used sleep(4); which gave my javascript enough time to do its thing. kind of an interesting workaround.

    probably not the efficient way to do it, but i didn't have enough time to figure out ajax. i'm definitely replacing it next semester once i get the hang of ajax though.
     

Share This Page