I am using PHP with PDO
Trying to retrieve records from a table using the email as a key. When the email is given directly in the sql statement, it works fine,
But when I am sending the email in a field "$bio_email", it does not work. The email field from the table is type "varchar"
I have tried several options but neither one works. The error that the system is returning is in the right hand side of the sql statement
this is my code
$bio_email = $applicantinfo->user_email; // email from a table
$sql = "SELECT * FROM tb_files_upload WHERE ";
$sql .= " email = 'applicant1@live.ca' "; // THIS WORKS FINE
//$sql .= " email = 'danilo.gonzalez@parkinson.ca' "; // THIS WORKS FINE
//$sql .= " email = $bio_email "; // DOES NOT WORK ... syntax to use near '@live.ca' at line 1
//$sql .= " email = {$bio_email} "; // DOES NOT WORK ... syntax to use near '@live.ca' at line 1
//$sql .= " email = '{$bio_email}' "; // DOES NOT WORK ... syntax to use near ''applicant1@live.ca'' at line 1
//$sql .= " email = '$bio_email' "; // DOES NOT WORK ... syntax to use near ''applicant1@live.ca'' at line 1
$biosketchs = Tb_Files_Upload::find_by_sql($sql);
Also in the same table I have a field "dateReceived". I would like to have the records that are 2.5 years old. Could you please help me with this.
I would try
$sql .= " email = '$bio_email' ";
for the dateReceived, just DATE_SUB for month, and for year inside.
dateReceived >= DATE_SUB(DATE_SUB(CURDATE(), INTERVAL 6 MONTH), INTERVAL 2 YEAR)
or let's not be stupid and use 18 months directly
$sql.= " AND dateReceived >= DATE_SUB(CURDATE(), INTERVAL 18 MONTH)";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.