我正在使用以下代码通过 fancybox 打开网址。我想在用户点击此按钮时更新 mysql 数据库。
目前的代码是:
<a class="fancybox fancybox.iframe more_info_btn" href="http://www.google.com">
<button style="cursor:pointer; padding:8px;">Test Live Session</button></a>
我想在用户点击按钮时更新mysql数据库,同时在fancybox中打开网址。
mysql更新如下
mysql_query("UPDATE tablename SET test_session_clicked='1'
WHERE reg_id=".$_SESSION['user_id21']");
答案 0 :(得分:1)
使用此
<a class="fancybox fancybox.iframe more_info_btn" href="http://www.google.com">
<button style="cursor:pointer; padding:8px;" id="btn">Test Live Session</button></a>
jQuery('#btn').click(function(){
jQuery.ajax({
type:'POST',
url:'your Php file path',
data:{'updated':true},
dataType:'json'
success:function(data){
alert(data.error);
}
})
})
php文件你的
if (isset($_POST['updated'])){
$queryStr = "UPDATE tablename SET test_session_clicked='1'
WHERE reg_id=".$_SESSION['user_id21'];
if ( mysql_query($qyeryStr)){
echo json_encode(array('error'=>false));
}else{
echo json_encode(array('error'=>true));
}
}