MySQL Forums
Forum List  »  Newbie

Re: How to query for rec's WHERE >= $start_date ?
Posted by: Fran Lee
Date: December 30, 2017 09:29AM

Good morning Peter and thank you for your help.

I'm a little confused by your last post and the included code.

1 - Not sure if you noticed in my previous post that I had realized that I should
- pass the date without any backticks...
- then test with the mysqli_real_escape_string function
- then put the backticks in the date string like...
- $date = "'2018-01-15'"; //quote backtick yyyy-mm-dd backtick quote:

this because the query WHERE clause wants the date in backticks like '2018-01-15'

// date not in a variable example
WHERE DATE(mytable.date) >= '2018-01-15'

// date in a string example

$date = "'2017-01-15'"; // quote backtick yyyy-mm-dd backtick quote
...
WHERE DATE(mytable.date) >= $date

Question 1: Did I unknowingly create a problem here?

2 - Your suggested code snippet took some digging to figure out...

$date = ( isset($_GET['date']) && !empty($_GET['date']) ) ?
mysqli_real_escape_string( $conn, $_GET['date'] ) :
"";

The ternary expression syntax (using the question mark and colon) was unknown to me... but after a little research I translated it to the following equivalent...

if ( isset($_GET['date']) && !empty($_GET['date']) ){
$date = mysqli_real_escape_string( $conn, $_GET['date'] );
}else{
$date = "";
}

Question 2: Did I translate it correctly?

Thanks again for your help Peter.

Options: ReplyQuote


Subject
Written By
Posted
Re: How to query for rec's WHERE >= $start_date ?
December 30, 2017 09:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.