0

I want to display records from database based on date if date is set else I want to display all records from table

sent_log.php

<form action="sent_log.php" method="POST">      
    <label>From</label>
    <input type="text" name="from_date">

    <label>To</label>
    <input type="text" name="to_date">  

<input type="submit" value="Submit" name="submit">
</form>

PHP Code

if(isset($_POST['submit']) && !empty($_POST['submit'])) {
    if (isset($_POST['from_date'],$_POST['to_date']) && !empty($_POST['from_date']) && !empty($_POST['to_date'])) {

    // code for display record based on date selected        

    }
} else {
   // code for display all records
}

SEE FULL CODE HERE Note: Don't consider the error in the link, Because code contains mysqli statements, I just want to display code not to display output, The code working fine without any error in my local pc!

Now my problem is when I open sent_log.php following code block working fine

else {
       // code for display all records
}

And when I select 2 dates and hit submit button, the following code block working fine

 if(isset($_POST['submit']) && !empty($_POST['submit'])) {
    if (isset($_POST['from_date'],$_POST['to_date']) && !empty($_POST['from_date']) && !empty($_POST['to_date'])) {

    // code for display record based on date selected        

    }
} 

But when I refresh the page I want to display all records But Now the output not changed, It displays records based on dates I selected Last time

I am looking output like

Display All records when first time load sent_log.php and when I refresh sent_log.php

If I select 2 dates from form in sent_log.php, load records based on 2 dates then I click refresh button load all records

From the Internet, To avoid form resubmission, It will be achieve By using 3 methods: Redirect to self, Ajax, session

But I don't know how to apply these 3 methods to my case

Prakash
  • 103
  • 2
  • 9
  • `But Now the output not changed, It displays records based on dates I selected Last time` ... well then reset them this time. You did it last time, do it this time – Drew Aug 30 '15 at 07:34
  • @Drew How to reset ? please tell me with code example, I don't know what you mean here "You did it last time" – Prakash Aug 30 '15 at 07:37
  • @Drew See my question else block only run when open sent_log.php and not working when refresh the page – Prakash Aug 30 '15 at 07:43
  • I know. It is as if the GUI is fine (as in Buttons), but when you right click and do RELOAD you have a problem, so you aren't following the gui. This is common, and developers expect this, right? but that is not want Grandma user is going to do – Drew Aug 30 '15 at 07:45
  • and kuddo's for using Prepared Statement. Code looks good – Drew Aug 30 '15 at 07:48

0 Answers0