I am in the middle of making a web based system for shows and each show as a different closing date for entries. The closing date is stored in a database. I need to display a export to excel button once the closing date has passed for each show.

I have already done the export to excel button and that works but it's clickable all the time, I need the button to only be clickable once the closing date for each show has passed. I'm thinking I need to check if the closing date in the database has passed compared to todays(current) date.

Not sure how it would work if each show has a different closing date though?

Below is what I came up with but know it's way off

<?php
$sql="SELECT closing_date FROM shows";
$result1 = mysqli_query($mysqli, $sql);
while($info = mysqli_fetch_assoc($result1)){
if(date('Y-m-d') > $info['closing_date'] ){
echo '<input type="submit" name="export_excel" class="btn btn-success float-md-right" value="Export to Excel">';
break;
}
elseif(date("Y-m-d") < $info['closing_date'] ){
echo '<a href="javascript:void(0);"><input type="submit" name="export_excel" class="btn btn-dark float-md-right" value="Export to Excel"></a>';
break;
}
}
?>

Use the disabled property:

<?php
$sql = "SELECT closing_date FROM shows";

$result1 = mysqli_query($mysqli, $sql);

while ($info = mysqli_fetch_assoc($result1)) {
    if (date('Y-m-d') > $info['closing_date']) {
        echo '<input type="submit" name="export_excel" class="btn btn-success float-md-right" value="Export to Excel">';
        break;
    } else {
        echo '<input type="submit" name="export_excel" class="btn btn-dark float-md-right" value="Export to Excel" disabled>';
        break;
    }
}
?>

The second if statement is unnecessary, since the export link will be clickable when the view date is after the closing date (not on or before the closing date).

In what format is the closing_date stored in MySQL? Is it stored as a timestamp field? A date field? You might not be able to do a PHP comparison like that depending on the format that MySQL stores the field as.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.