I want to run a select statement with PHP using multiple '?'. How do I do that? I think the following code should do that, what is wrong?
$con = mysql_connect("database","login","password");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("posdictionary", $con);
$stmt = $con->prepare("SELECT * FROM WordPOS WHERE WORD LIKE '?%' AND pos LIKE BINARY '%?%'");
$stmt->bind_param('ss', $pattern, $pos);
$pattern = $_POST["pattern"];
$pos = $_POST["pos"];
$value = "";
if ($stmt->execute()) {
while ($row = $stmt->fetch()) {
$value = $value . $row['word'] . " " . $row['pos'] . "<br />";
}
}
UPDATE:
The answers below are great. I had an error in my PHP the '?%' is not legal in php sql statement. The query should look like this:
$pattern = $_POST["pattern"] ."%";
$pos = "%". $_POST["pos"] ."%";
$stmt = $con->prepare("SELECT word, pos FROM WordPOS WHERE word LIKE ? AND pos LIKE BINARY ?");
Then follow the rest of the answers.