I'm getting this error:
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement
code:
$stmt = $sql->prepare("SELECT name, site, message, `when` FROM messages WHERE message LIKE '%?%'");
$stmt->bind_param('s', $_GET['search']);
$stmt->execute();
$result = $stmt->get_result();
I'm trying to get the user input into the prepared statement.
This code works fine but is insecure against SQL injections:
$result = $sql->query("SELECT name, site, message, `when` FROM messages WHERE message LIKE '%" . $_GET['search'] . "%'");
$par="%" . $_GET['search'] . "%" ,$stmt->bind_param('s',$par);?, don't put it inside the string delimiters. A question mark inside a string counts as a normal question mark character. If it were a parameter placeholder, how could you ever use a normal question mark in a string?