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.

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?