Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to use ajax perform this??

    PHP Code:
    <script type="text/javascript">    
                            var answer=confirm("Do you want to update your email?");                
                                if(answer==true)
                                {
                                <?php
                                mysql_query
    ("update user set u_email ='$email' where u_user='$username'");
                                
    ?>
                                
                                alert ("You choose update your email.");
                            
                                }
                                if(answer==false)
                                {
                                alert ("You had rejected to update your email.");
                                //answer=0;
                                }
                                
                        </script>
    i face a problem that it will still perform update query if i click cancel, how to use ajax to solve this?? somebody help me pls...

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can't do what you are doing with the current code you have. By the time the page loads the query has already ran whether or not you hit ok/cancel on the confirm. You need to use AJAX to post to a PHP script that will execute the query.

    I suggest using jQuery and using $.post to do the ajax.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can you show me how?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Can you show us that you even tried to do this yourself?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Oct 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how i can search for the solution?

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    For starters look up jQuery $.post for how to use it. Create your php script for it, then include the jQuery library on your page.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •