I have the following code:
<?php
$stmt = $db->prepare("select * from products where `price`=:price and `id`=:id and date => NOW()");
$stmt->bindParam(":price", $_GET['price'], PDO::PARAM_STR);
$stmt->bindParam(":id", $_GET['id'], PDO::PARAM_INT);
if ($stmt->execute() == true){
if($stmt->rowCount()==1){
echo "1 row";
}else{
echo "more than 1 row";
}
}else{
echo "nothing returned";
}
?>
If there is 1 match in the db I get :1 row outputted
If more than 1 row i still get : 1 row outputted
and if there is no matches I get:
PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘=> NOW()’ at line 1
Please can someone help with this
Thanks
Ps. the db connection definitely works!
I don’t know why you’d only experience this problem under certain conditions, but it appears that your comparison operator has switched characters.
date => NOW()should be
date >= NOW()At first glance, I assumed it was because
DATEis a reserved word that you’re using as a column name without backticks. But, according to the docs: