dongshi4589 2015-11-30 12:56
浏览 13
已采纳

在页面加载时插入MySQL行[关闭]

This is going to be my first question on stackoverflow so I hope I'm doing it right =)

I want to insert a MySQL record when the page loads. I have a form and a database. I want to be able to see in my database if the user has visited the form page( obviously without submitting the form ). I know how to do it on page submit, but how can I fill up a MySQL row on page load?

Example of my wish: example

I'm very curious how this can be done . Thanks in advance!

  • 写回答

1条回答 默认 最新

  • duanjiaolia97750 2015-11-30 13:03
    关注

    You need to use AJAX for this kind of stuff..

    update.php

    <?php
        mysqli_query("INSERT INTO bla (column1, column2) VALUES (value1, value2)") or die(mysqli_error());
    

    ?>

    jQuery:

    $(document).ready(function(){
        $.ajax({
            type: "GET",
            url: "update.php"
            success: function(data) {
                // success
            }
        });
    });
    

    This is a really basic way, you could use "$_GET" to send data in your AJAX request etc.

    -

    Edit: @David had a fair point in the comments. Try that first.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?