简体   繁体   中英

SQL query after clicking a link

I have a link that i want to execute a query to the database after it's clicked and then reload the page. From what i read, it could be done using javascript, but i can't figure it out.

EDIT

Forgot to mention that i want to send 4 variables to the script and i can't use GET because i have htaccess set to modify my URL.

Here is the jquery code which will solve your issue. Write this code in a javascript function. onclick event of that button should call this function. Write all your db coding in yourpage.php.

url = "yourpage.php";

    $.get
    (
        url,
        {
            'act'       :'getdata'
        },
        function(responseText)
        {           
            strData = responseText;

            $('#div_id').html(strData);

        },
        "html"
    );

It will work.

Check this link http://api.jquery.com/jQuery.get/

In this case you need to use these concepts:

  1. A JavaScript function to submit the from values
  2. PHP code

You need to user these code:

 <a href = "javascript:submit()">Submit</a>
 <form action = "$_SERVER['PHP_SELF']" method = "post">
 <input type = "hidden" value = "some value"/>
 <input type = "hidden" value = "some value"/>
 <input type = "hidden" value = "some value"/>
 <input type = "hidden" value = "some value"/>
 </form>
<?php
//Connect to the database
$conn = mysqli_connect('host','user','password','db_name');
if($conn){
     $query = "SOME QUERY";
     $result = mysqli_query($conn, $query);
}
?>

In your JavaScript function write a code to submit the from clicking the submit link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM