how can i pass the selected value date to another page?

I have this function where i want to pass the month and year according to the date drop down that is chosen by the user. But can’t seem to get the selected month and year. But instead, i got the month and year for now (which is April 2020). Can any one show me how can i achive this? I mean how can i pass the month and year selected to my allreport-summary.php page. It would be better if you guys can show me examples of codes on how can i implement this. Any help will be appreciated. Thank you so much. cheers!

     <div class="row">
                  <div class="col-4 my-auto">
                    <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>">
                  </div>
                  <div class="col-4 my-auto">
                    <select class="form-control" id="seller">
                      <option value="">Select All</option>
                      <?php
                      $sql = "SELECT * FROM sellers ORDER BY seller_registered";
                      $query = $conn->query($sql);
                      while ($row = $query->fetch_assoc()) {
                      ?>
                      <option value="<?php echo $row['id'];?>"><?php echo $row['seller_fullname'];?></option>
                      <?php } ?>
                    </select>
                 
                  </div>
                  <div class="col-4">
                    <button type="button" class="btn btn-info" onclick="loadreports();">
                      <i class="nc-icon nc-zoom-split"></i>
                    </button>
                  <a href="allreport-summary.php?month=<?php echo date('Y-m');?>">
                    <button type="button" class="btn btn-info" style="height: 40px;">
                      <i class="fa fa-file-excel-o"></i> &nbsp;  &nbsp;Export All Report
                    </button>
                   </a>
                      </div>

how can i pass that <a href="allreport-summary.php?month=<?php echo date('Y-m');?>"> according to the selection of <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>"> ?

Well, if you use an anchor ( < A HREF ), the user can see it as it is in the URL line at the top of the browser. If you wish to pass the data to another page, there are two ways to do it so that it is hidden from the user.

1 - Use a form field and post the page to the second page. Just use a form field and set up the form to post to the second page as needed. If the selected value is in a drop-down select, it is already in a form and is available to the next page if posted it to. So just set the …

2 - Use $_SESSION array. For this, you just start a session at the beginning of every page. Then, save the dates needed inside the $_SESSION array once selected by the user. This would be handled in the original form page as a PHP routine and would need you to post to the same page. Then, the PHP code would save the date in the session and move to the second page which would read the session array data.

Now, that covers how to pass data on. Now, how to handle dates. First, I am assuming you have a database table that includes a list of dates. You mention only months. Are years involved, too? Normally, you would just use one “datetime” field. There are so many different functions for dates and times and are easy to use. Normally, you would not separate a date by month and year. Just use the correct function to access them as needed. With that said, let’s explain the process.

First, you have a form that allows the user to alter data. You can post that data to the same page or a different page. On the original page, you would need to create a drop down with year and another with month. Or if using Bootstrap as I suspect, you can use a “date-picker” which lets the combine both into one datetime field. Once the user selects the date options, just POST the data to the next page. This is handled inside the < FORM > tags. Loosely something like this:
< form action=“allreport-summary.php” method=“POST”> . . . rest of form . . . < /form >
Once the user presses the submit button, the page is posted to the second page. In that page, you need to just read the data from the first page. $requested_date = filter_input($_POST[“requested_date”];
Just an example! Then, on the second page, that data can be used as needed. If you have two separate fields for year and month, you would need two lines to gather the separate data. Otherwise, you can pull out the year and month from the one date. Easy to do.

Not sure if all this is what you are asking for, but, hope it helps… Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service