Ho Do I Push a Button and Run an SQL Statement?

Discussion in 'MySQL' started by kuttappan, Jun 1, 2010.

  1. #1
    I have a PHP page the accesses a MySQL database. I want to add the capability of sending an SQL statement to the database when the user pushes one of three buttons on the page, for example,
    Code:
    The intent is to make a quick change rather than to go into the full edit page. It seems like this should be relatively simple but I have spent hours trying to find out how to do it (obviously, I am a newbie). Can someone explain how to do this?

    Any help will be greatly appreciated.
     
    kuttappan, Jun 1, 2010 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Is your intent to not reload/refresh the page they are viewing? If that is the case you will use AJAX. That term gets thrown around a lot and here's what it actually means in your situation:

    When clicked your button triggers a Javascript function that submits to .php script. That php script would execute whatever code you want and it would return some data to the Javascript function so the page the user is viewing could be updated to the status of that scripts execution without refreshing/reloading the page they are viewing.

    What you are asking to do is a very simple AJAX task, google for an AJAX tutorial and most likely you can find one that will be 90% of the code you need to implement your solution.
     
    plog, Jun 1, 2010 IP
  3. phpmatt

    phpmatt Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Create a form with action="update1.php", include the necessary values in the form, may be hidden if they are taken from the page and not user input.

    In update1.php execute the SQL and redirect back to the page.
     
    phpmatt, Jun 22, 2010 IP