OiO.lk Blog PHP PHP and MySQL error unknown column '31327d3993acf3e1b0582ab64604b2eb' in 'where clause'
PHP

PHP and MySQL error unknown column '31327d3993acf3e1b0582ab64604b2eb' in 'where clause'


This error is showing up in the PHP error_log and I’m trying to figure out why and how it is happening. Obviously, I don’t have a field name of ‘31327d3993acf3e1b0582ab64604b2eb’ in the table. It stems from a user entry form of one field that lets the user do a search for a phrase in four fields. Here is the SQL:

SELECT COUNT('id'), users.username 
FROM listings 
LEFT JOIN users ON listings.owner = users.user_id 
WHERE dateposted > :cutoffdate 
AND (title LIKE :search 
    OR body LIKE :search1 
    OR location LIKE :search2 
    OR username LIKE :search3
)

and here is my php. The error is happening on the first line

$stmt = connect()->prepare($sql);
$stmt->execute(['cutoffdate' => $cutoffdate, 
                'search' => "%$searchstring%", 
                'search1' => "%$searchstring%", 
                'search2' => "%$searchstring%", 
                'search3' => "%$searchstring%"]);
    

Is this problem coming from me using the entered value to search for multiple times in my prepared statement?



You need to sign in to view this answers

Exit mobile version