dougai8673 2019-05-30 06:28 采纳率: 100%
浏览 91

当用户在php中单击时,尝试使用javascript函数运行mysql查询特定时间

When user click claim button, i want to run javascript function every 5 sec. After i build up this code, and clicked the button but the script doesn't work. I'm not good at javascript at all. All i know is some php and mysql.

When user clicked claim button, the function send() should call payout() function and run this crul() function which is inside payout() function. I don't know where i make mistake as i don't know much javascript.

this is the button function i build up. don't know if it wrong or not.

<button onclick="send()" class="btn-success"><i class="fas fa-exclamation-circle"></i> Claim <i class="fas fa-exclamation-circle"></i></button>
<script>
function send() {
   setInterval(function(){ payout(); }, 5000);
}
</script>

This is the function payout()

function payout(){
    $sql = $conn->query("UPDATE wallets SET balance = balance - 1 WHERE wallet = '$wallet' " );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://faucethub.io/api/v1/send");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
            "api_key=$apikey&to=$wallet&currency=$shortcurrency&amount=$doge ");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $server_output = curl_exec ($ch);
    curl_close ($ch);
}

The result should be payout() function should send to that $wallet every 5 sec

  • 写回答

0条回答 默认 最新

    报告相同问题?