Jump to content

A php function - retrieval ban for present and future?


samanj

Recommended Posts

Hi,

 

I have made a database linked with php that I use a html form for.

The HTML form requests a particular date to retrieve, and the php form it is linked to then retrieves data from the MySQL database from that date.

 

My question is: I want there to be a restriction so that the retrieval can only be for dates before the present date (and certainly not any date in the future).

 

e.g. if it is 6th July 2020, then the database can only retrieve from the 5th July 2020 and before. (7th July 2020 onwards also is not allowed.)

Is there a way I can do it? Anyone who can guide me to a particular code function or something of that sort - I would be deeply grateful as my searches have not come up fruitful.

Edited by samanj
clarity
Link to comment
Share on other sites

At it's most simplest, your solution is called an "If statement". 

The HTML page loaded into the User's browser submits data to your PHP for processing.  As as essential part of that processing, you should validate the supplied data values against your chosen criteria. 

In this case, they need to enter a valid [Character Representation of a] Date that must be earlier than the current date.

If the supplied data does not match your criteria, then you send error back message(s) that the HTML (or Javascript) has to show to the User.

Regards, 
   Phill  W.

 

Link to comment
Share on other sites

After years of fighting with my server's time zone (shared hosting),  I now have these lines of code on my PHP date page (thanks to Barand):

date_default_timezone_set('America/Los_Angeles');
$date = new DateTime();

After you implement the suggestions posted above, these two lines of code on your PHP page(s) will save you the aggravation of wondering why your PHP / mySQL seems to always be off by an hour or two :-)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.