0
I made a button adicionar amigo
, as in social networks, except that I use form to do this, it sends the user to another page. Wanted some dynamic way without updating the page, when clicking the button is made the Insert in the database and returns the disabled button not letting the user to trigger the button more than once.
This is the page where the user adds a user:
php friends.
<a class="btn btn-primary" amigo_id="<?php echo $id; ?>">Adicionar amigo</a>
When clicking the button would have to run this file in the background without updating the page.
add-friend.php
<?php
session_start();
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$conn->set_charset("utf8");
if ($conn->connect_error) {
die("<font color='red'>A conexão falhou: </font>" . $conn->connect_error);
}
$sql = "INSERT INTO amigos (id_usuario,id_amigo,data_adc)
VALUES ('$_SESSION[UsuarioID]', '$_GET[id]', now() )";
if ($conn->query($sql) === TRUE) {
echo "Amigo adicionado!";
} else {
echo "Erro: " . $sql . "<br>" . $conn->error;
}