0

When I run this query directly in phpMyAdmin, it runs fine.
But using prepared statement with PHP it doesn't.

The query is supposed to check if the string from the session variable 'number' starts with any number from the column bin.

It's something like: if the number($_POST['number']) starts with any value (sequence of numbers) from column bin, it will return all columns from this bin row.

What am I doing wrong?

Here's the code:

if($r = $mysqli->query("SELECT * FROM bins WHERE ? LIKE CONCAT(`bin`, ?)")){
        $any = '%';
        $r->bind_param("ss", $_POST['number'], $any);
        $r->execute();
}

I'm getting the error:

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 '? LIKE CONCAT(bin, ?)' at line 1

user4857867
  • 127
  • 9

0 Answers0