<button onlick="myFunction()">Click me</button>
<?php
function myFunction() {
$con = mysqli_connect("mysql.hostinger.no", "u452849516_altge", "password", "u452849516_altge");
$query = "SELECT * FROM altbruker ORDER BY RAND() LIMIT 1";
mysqli_query($con, $query);
$results = mysqli_query($query);
var_dump($results);
}
?>
答案 0 :(得分:2)
答案 1 :(得分:0)
js on click cant调用php代码你可以使用AJAX来执行以下操作
<button>Click me</button>
$("button").click(function(){
$.ajax({url: "the_php_page.php", success: function(result){
alert(result);
}});
});
<_>在the_php_page.php中执行查询
$con = mysqli_connect("mysql.hostinger.no", "u452849516_altge", "password", "u452849516_altge");
$query = "SELECT * FROM altbruker ORDER BY RAND() LIMIT 1";
mysqli_query($con, $query);
$results = mysqli_query($query);
var_dump($results);