mardi 12 mai 2020

How can I pass a value of a variable from one If-Statement to another in PHP?

I got the problem, that I request a date as an Input from the user to change an SQL-Query which generates an HTML Table. After that the user can click an export button to download an Excel-File, which should only include the selected period of time the user has chosen. The problem is that I don´t know how to pass the selected date from the first IF-Statement to the IF-Statement of my Export-Button. The SQL-Query doesn´t take the selected dates of the user but instead the default value of today, that is declared as default. Is there an option the pass the selected dates to the other IF-Statement?

Here are the important parts of my code:

$datumstart =date('Y-m-d');
$datumende =date('Y-m-d');

....


if(isset($_REQUEST['datumstart'])){

    $datumstart = $_REQUEST['datumstart'];  

    if(isset($_REQUEST['datumende'])){
        $datumende = $_REQUEST['datumende'];

$query = "SELECT * FROM pw WHERE date between '$datumstart' AND '$datumende'";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
}
}


if(isset($_POST["export"]))
{



$query = "SELECT * FROM pw WHERE date between '$datumstart' AND '$datumende'";

....
}

Aucun commentaire:

Enregistrer un commentaire