Button can only be clicked after 24 hours after click

Asked

Viewed 103 times

0

Hello guys I have a site and want the following ( I can not do, nor found on the net ), A button that after the click is registered in db, after that the button can only be clicked after 24 hours, the check-in table 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 insert button on db, and after 24 hours the button releases again and so on

(NAME CAN PUT TO INSERT ANYONE EX: Alfonso, DPS I CREATE A FORM)

  • Your question is misspelled. After the button is clicked and inserts in db, the button is unavailable for 24 hours for all users?

  • Not just for the user who clicked the button

  • In this case it has to be a login page (to characterize that it is unique) with one more condition in the Where clause, that is, where the difference between the last recorded date and the current date is greater than 24 hours. If these conditions are met release the button to be clickable.

  • If any answer has solved your problem mark it as accepted. See how in https://i.stack.Imgur.com/evLUR.png and see why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

  • This game is very complicated for me, rsrsrs, but anyway you have to login to enter, that’s where you will recognize and deactivate the button

  • I couldn’t see that button, maybe they use cookies created when you log in

  • I already have the login system, password , registration, session cookie my dB weighs some 5MB only need this damn button that only the owner in Yuup has (I know him more he does not pass anything) he says it’s easy to do except that on his site he switched the button for an insert when he enters the client.php to be easier pros users more before said it was a button that was in the /me.php

  • A guy in the business also did more he lost his mega is no time to do because he has other projects...

  • has how to give Insert in all users of db without entering the site type without me entering the site it add auto

Show 4 more comments

2 answers

2


Instead of using a "time" field like int change to the type datetime and put the value default NOW():

ALTER TABLE checkin CHANGE hora DATETIME default CURRENT_TIMESTAMP

this way you do not need to enter the time of the record, 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 bring records does not release the Insert

  • Unanswered to the question

  • Ué, isn’t it only to enter the record if it has passed 24 hours after the last Chekin? not very secret, you will only need to complete with the data of the user in question WHERE nome = ‘algumacoisa’

2

Create a table that contains columns, for example, nome and senha to characterize that the user is unique and also contains a column data of the kind DATETIME

Do a SELECT and check for registration, if any disable the button.

See below for an example with mysqli

PHP

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

        }
}

HTML

..............
..............
<button type="button" <?php echo $disabled ?>>Click Me!</button>
..............
  • no and so, do not need the login etc that I already have can leave only the same name, let’s assume: I already logged in from the Dashboard has a button that when clicked can only be clicked again after 24 hours, no need to check if the user has more check if the button has already been clicked in the last 24 hours

  • @Alaskah, the way I understand it, I don’t think even God can do it. But the way goes through my answer and @Hebert de Lima’s, see if you can adapt to your needs.

  • Of course it is possible, has in this site: http://yuup.online/trocas the left side has the name picoles, there it shows how it works, now it works when you enter the game, more before it is in a button I want to do in this mode in OBS button: the logging talking is to enter the game

Browser other questions tagged

You are not signed in. Login or sign up in order to post.