___ erkimt ___ Button can only be clicked after 24 hours after the click ______ qstntxt ___
Hello everyone, I have a website and I want the following (I can not do it, nor found it on the net), a button that after the click is registered in db, after that the button can only be clicked after 24 hours, check-in is like this:
$servername = "localhost";
$username = "USUARIO";
$password = "SENHA";
$dbname = "NOME_DB";
$conn = new mysqli($servername, $username, $password, $dbname);
if (!$conn) {
die("Conexão falhou: " . mysqli_connect_error());
}
$result = $conn->query("SELECT COUNT(*) FROM checkin WHERE nome='$nome' AND senha='$senha' AND data > DATE_SUB(NOW(), INTERVAL 1 DAY)");
$row = $result->fetch_row();
if ($row[0] > 0) {
//vai desabilitar o botão
$disabled = "disabled";
} else {
/****** Verifique se o usuário existe ******/
$result = $conn->query("SELECT COUNT(*) FROM checkin WHERE nome='$nome' AND senha='$senha'");
$row = $result->fetch_row();
if ($row[0] > 0) {
/****** Se existir faz UPDATE na data com data atual *****/
$conn->query("UPDATE checkin SET data=now() WHERE nome='$nome' AND senha='$senha'");
}else{
/****** se NÃO existir faz o INSERT ********/
$conn->query("INSERT INTO checkin (nome, senha, data) VALUES ('$nome', '$senha', now())");
}
}
EX: I click the button inserted in the db, and after 24 hours the button releases again and so on
(NAME CAN PUT TO INSERT ANYONE eg: Alfonso, DPS I CREATE A FORM)
Instead of using a "time" field of type nome
change to type senha
and set data
DATETIME
:
%code%
In this way you do not have to insert the registration time, it will be inserted automatically with the time of the server.
before making a new insert:
%code%
If the select fetch records does not release the insert
Create a table that contains columns for example %code% % %code% and to characterize the user to be unique and which also contains a column %code% Type%% %code%
Make a SELECT and check for registration if there disable the button.
The following is an example with mysqli
PHP
..............
..............
<button type="button" <?php echo $disabled ?>>Click Me!</button>
..............
HTML
$servername = "localhost";
$username = "USUARIO";
$password = "SENHA";
$dbname = "NOME_DB";
$conn = new mysqli($servername, $username, $password, $dbname);
if (!$conn) {
die("Conexão falhou: " . mysqli_connect_error());
}
$result = $conn->query("SELECT COUNT(*) FROM checkin WHERE nome='$nome' AND senha='$senha' AND data > DATE_SUB(NOW(), INTERVAL 1 DAY)");
$row = $result->fetch_row();
if ($row[0] > 0) {
//vai desabilitar o botão
$disabled = "disabled";
} else {
/****** Verifique se o usuário existe ******/
$result = $conn->query("SELECT COUNT(*) FROM checkin WHERE nome='$nome' AND senha='$senha'");
$row = $result->fetch_row();
if ($row[0] > 0) {
/****** Se existir faz UPDATE na data com data atual *****/
$conn->query("UPDATE checkin SET data=now() WHERE nome='$nome' AND senha='$senha'");
}else{
/****** se NÃO existir faz o INSERT ********/
$conn->query("INSERT INTO checkin (nome, senha, data) VALUES ('$nome', '$senha', now())");
}
}