too long

I've created a page where the user gets some information based on two dates (like 01/01/2019 and 04/04/2019). The user chooses both dates, which are sent to my sql query.

My issue is that I need to press the submit button twice for the dates to update.

From what I could see, the code is getting the dates from the previous submit and not the current one. For example, if I change one of the dates from 01/01/2019 to 01/02/2019, it will still be showing the info with 01/01/2019 as a date. I know that because I put some echos on the code and I can see that it's getting the previous value.

I've already tried the solutions from in php, why input form when submit it takes 2 times pressed, but nothing worked.

Here is the code where the user inputs the dates:

 <form action="code.php?titulo=Entrada_De_Soja_por_Variedade&codpag=soja&ini=<?php echo $ini ;?>&fin=<?php echo $fin ;?>" method="post">
    <input name="ini" id="ini"  type="date" value = "<?php echo $ini2 ?>" placeholder="<?php echo $ini ?>" >
    <input name="fin" id="fin" type="date"  value = "<?php echo $fin2 ?>" placeholder="<?php echo $fin ?>">
    <input style="width: 120px; height: 30px; font-size:14px;" type="submit" value="Search" />
</form>

$ini is the initial date and $fin is the final.

On the same code.php, I use:

$ini = $_POST['ini'];
$fin = $_POST['fin'];

On the sql query, I use:

$ini = $_GET['ini'];
$fin = $_GET['fin'];

What I need to know is if I'm using the right strategy to with $_POST and $_GET and if there is a way to fix this problem.

Thanks in advance and feel free to ask for more details if you need.

You can't pass variables via "POST" and recieve them via "GET".

Also, you don't need to put the vars into the action URL, as they get appended automaticly when using method "GET".

If you want the dates visibile inside the URL (to share the link) you could use this on the form-page:

 <form action="code.php" method="get">
<input name="ini" id="ini"  type="date" value="<?php echo $_GET['ini']; ?>" placeholder="<?php echo $ini; ?>" >
<input name="fin" id="fin" type="date"  value="<?php echo $_GET['fin']; ?>" placeholder="<?php echo $fin; ?>">
<input style="width: 120px; height: 30px; font-size:14px;" type="submit" value="Search" />

For more information on how "GET" and "POST" work, have a look at this:

https://www.tutorialspoint.com/php/php_get_post.htm