[英]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.
从我读到的内容来看,可以使用 javascript 来完成,但我无法弄清楚。
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.忘了说我想向脚本发送 4 个变量,但我不能使用 GET,因为我设置了 htaccess 来修改我的 URL。
Here is the jquery code which will solve your issue.这是将解决您的问题的 jquery 代码。 Write this code in a javascript function.
在 javascript 函数中编写此代码。 onclick event of that button should call this function.
该按钮的 onclick 事件应调用此函数。 Write all your db coding in yourpage.php.
在 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/检查此链接http://api.jquery.com/jQuery.get/
In this case you need to use these concepts:在这种情况下,您需要使用以下概念:
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.在您的
JavaScript
函数中编写代码以通过单击提交链接提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.