George_Fal 2020-01-29 01:30 采纳率: 0%
浏览 51

Onclick插入到SQL

emphasized texti need help creating an onclick() function for an tag, that when it is activated it writes to 3 different rows in an MSSQL DB.

Im trying to figure it out, but my knowledge is not that great, i know i might have to use AJAX for this work.

Using MSSQL 2017, PHP 7.1

MY end result is to create a Click counter, the name of the section clicked and the date/time it was clicked.

IF anyone can help me, i appreciated very much.

Thank you.

Thanks for the guidance!!!

Edit

test.php

$counterServer = "TEST\TEST";
$counterconnection = array( "Database"=>"TestingCounters","UID"=>"User","PWD"=>"1234","CharacterSet"=>"UTF-8");
$finalcon = sqlsrv_connect( $counterServer, $counterconnection);

if( !$finalcon ) {

     die( print_r( sqlsrv_errors(), true));
}



$sequel = "INSERT INTO dbo.CounterTest(Visit,Date_Value,Section) 
 VALUES('1',getdate(),'Kitchen')";

and my dumb logic , but i later realized i dont need to use a button but an anchor.

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <button action="test.php"  method="post">click</button>
  </body>
</html>

Final Working Test HTML

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <script type="text/javascript"
            src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
    </script>
    <script type="text/javascript">


function ctest(){
  $(document).ready(function () {


$.post('test.php',   // url
   { Section: 'something.' });

});

}


    </script>
</head>
<body>
    <h1> jQuery post() method demo
    </h1>


<a href="" id="sendbtn" onclick="ctest();">click me</a>

    <p>
    </p>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • weixin_33711641 2020-01-29 05:30
    关注

    Use Jquery library for Ajax request then add the onclick event on the button to make the ajax request.

    https://www.tutorialsteacher.com/jquery/jquery-post-method

    You can see the example of ajax on this link. The url should be where your php script is to send the 3 different rows in an MSSQL DB.

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记