Button can only be clicked after 24 hours after the click

0

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:

-- Check-in Table
CREATE TABLE IF NOT EXISTS 'checkin' (
-- AUTO INCREMENT... ID DO CLICK
'id_click' int(10) unsigned NOT NULL AUTO_INCREMENT,
-- Username do usuario isso você não precisa add um formulario pra pegar o nome < ja tenho >
'nome' varchar(64) NOT NULL ,
'hora' int(64) NOT NULL,
-- Não sei se isso é o suficiente
PRIMARY KEY ('id_click')
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=529 ;

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)

    
asked by anonymous 19.07.2018 / 01:26

2 answers

2

Instead of using a "time" field of type int change to type datetime and set default NOW() :

ALTER TABLE checkin CHANGE hora DATETIME default CURRENT_TIMESTAMP

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:

SELECT hora FROM checkin WHERE hora > DATE_SUB(NOW(), INTERVAL 1 DAY)

If the select fetch records does not release the insert

    
19.07.2018 / 02:19
2
___ 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)

    
______ azszpr316238 ___

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

    
______ ___ azszpr316253

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())");

        }
}
    
___
19.07.2018 / 04:18