0

I have a table, eventID, remainingTime, serverRestart, autoRestart

When the user clicks submit on my form, it updates the columns to the values I need, but they can continuously click the button and always update the database. I am wanting to disable the submit button after they click it once. I have tried many different options on SOF but nothing works how it should.

What I have tried is the following

$checkForUpdate = "SELECT `remainingTime` FROM `serverrestart` WHERE eventID = 1";
$result = mysqli_query($dbCon, $checkForUpdate);

and my form;

<?
                    
                    while($row = mysqli_fetch_array($result)){
    if(strpos($row['remainingTime']) === false) {
        echo "<button class='btn btn-primary' type='submit' name='restart' disabled>Initiate Restart</button>";
    } else {
        echo "<button class='btn btn-primary' type='submit' name='restart'>Initiate Restart</button>";
    } 
}
?>

I also used this -> How to disable button based on Database? as a guide also, but the button is always disabled.

So in short.. The user clicks "Initiate Restart" the database fields populate with their values, and the page refreshs, I am wanting the page to refresh but disable the button based on the value in the field ramainingTime which is always 30

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • what is `30` anyway? 30 seconds? 30 minutes? 30 hours? you should have saved a timestamp of the date until the user is allowed to click again, then you can just compare it to the current time – Kevin Feb 09 '21 at 00:54
  • Well, for starters, `strpos($row['remainingTime'])` lacks the second parameter. Do you have [error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) turned on? – El_Vanja Feb 09 '21 at 02:02
  • Its 30 minutes. The way the data is sent to that tabel it inserts `30` into the row. Its called from another file not created by me. – Dan Andrews Feb 09 '21 at 03:52

1 Answers1

0

Problem Solved, using > How to disable button based on Database?

Method:

$checkForRestart = "SELECT `serverRestart` FROM `serverrestart` WHERE `eventID` = 1";
$result = mysqli_query($dbCon, $checkForRestart);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);

and the html

<? if (!in_array('1', $row)) {echo "<button class='btn btn-primary' type='submit' name='restart' >Initiate Restart</button>";} else {echo "<button class='btn btn-primary' type='submit' name='restart' disabled>Initiate Restart</button>";} ?>