I have a system of downloading songs with a download button and I would like that when I click the button, it inserts a line in the database without leaving the page.
Now what I did is open a new page that does the insert:
For each song has this code in the table row:
<form method="post" action="inseremusica.php">
<input type="text" name="id">
<button type="submit">
</form>
inseremusica.php
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "INSERT INTO euk_lista_downloads (idmusica, data)
VALUES ($_POST['id'], date('d/m/Y H:i:s', time()))";
$conn->query($sql);
$conn->close();
?>