简体   繁体   English

单击mailto:或tel:链接时触发INSERT查询

[英]Trigger an INSERT query when mailto: or tel: links are clicked

I have a php page which is designed around mobile functionality and loads information from search criteria, information is gathered on the page and that information is then POSTed automatically to a database when the page opens to record the visit and works flawlessly, this is the code: 我有一个php页面,该页面围绕移动功能设计,并从搜索条件中加载信息,信息在页面上收集,然后当页面打开以记录访问并完美运行时,该信息会自动过帐到数据库中,这是代码:

$mysqli = new mysqli($servername, $username, $password, $dbname);
$stmt = $mysqli->prepare("INSERT INTO `analytics_scans` (`ip_address`, `property_id`, `address`, `town`, `agent_name`, `office`) VALUES (?,?,?,?,?,?)");
$stmt->bind_param('sissss', $_SERVER['REMOTE_ADDR'], $id, $address, $town,     $agent, $office);
$stmt->execute();

On this page are 3 'buttons/images' Call, Mail and Share what I want to do is record these events into 3 separate tables exactly as in the code above without leaving the page, I can't reload it because it will record a further page visit. 此页面上有3个“按钮/图像”,呼叫,邮件和共享我想要做的就是将这些事件记录到3个单独的表中,与上面的代码完全相同,而没有离开该页面,我无法重新加载它,因为它将记录一个进一步的页面访问。 I can't duplicate the one shown and point to the other tables as it's the click it has to record. 我不能复制显示的一个并指向其他表,因为这是它必须记录的点击。

Ideally something like an onClick function would be the solution but I'm sure that's not possible without leaving the page. 理想情况下,像onClick函数之类的东西将是解决方案,但是我敢肯定,如果不离开页面,那是不可能的。

Any help is appreciated. 任何帮助表示赞赏。

You can use Ajax (with jQuery for example). 您可以使用Ajax(例如jQuery)。

Example: 例:

<a href="mailto:xxx@xxx.de" onclick="return javascript:log('mail_clicked');">Write email</a>
<a href="#" onclick="return javascript:log('share_clicked');">Share</a>

In jQuery: 在jQuery中:

function log(action) {
    $.get('./log.php?action=' + action);
    return true;
}

In the log.php: 在log.php中:

<?php

$db = new MySQLi(...);
if($_GET['action'] == "mail_clicked")
    $db->query("INSERT INTO `mail_clicked` ...");
else if($_GET['action'] == "share_clicked")
    $db->query("INSERT INTO `share_clicked` ...");

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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