I'm trying to make it just send to the database when I click the button however every time the page is loaded it sends even not clicking the button. This is the code I'm using
<script>
var text = "foi clicado"
</script>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
document.getElementById("d").innerHTML = "<?php
include 'conect.php';
$ts = "<script>document.write(text)</script>";
$TS2= $ts;
$sql ="INSERT INTO 'ss'('nome') VALUES ('$TS2')";
$query = mysqli_query($link, $sql) or die(mysqli_error());
?>";
}
</script>
If you can connect to the database via javascript and be safe, I'm happy to hear it too.