开发者

On click INSERT INTO mySQL without updating the current page

开发者 https://www.devze.com 2023-03-30 09:46 出处:网络
I am working with PHP and mySQL. On page1.php there will be an image th开发者_StackOverflow社区at when the user clicks on it there will be a query that inserts into mysql some data. How can I do this

I am working with PHP and mySQL. On page1.php there will be an image th开发者_StackOverflow社区at when the user clicks on it there will be a query that inserts into mysql some data. How can I do this without reloading the page or transferring the user someone else and change the image?

What I did so far is to do this but with reloading the page.

Thanks for your ideas/examples.


It is as simples as executing the post method of jQuery library.

Here is an example that calls a PHP script when clicking any image.

$(document).ready(function() {
    $("img").click(function() {
        $.post("executequery.php");
    });
});

In the "executequery.php" you would need to build the SQL and execute it.

Here is the documentation of the method. http://api.jquery.com/jQuery.post/


Using jquery, add an ajax call to a php script which should be able to run the insert script and return a success message.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号