donglu5728 2015-06-05 14:19
浏览 165

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

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:

$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. 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.

Any help is appreciated.

  • 写回答

1条回答 默认 最新

  • downloadTemp2014 2015-06-05 14:23
    关注

    You can use Ajax (with jQuery for example).

    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:

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

    In the 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` ...");
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么