I'm attempting to use a SQL LIKE clause with mysqli prepared statements.
I have already tried other examples such as
$sysName = "{$_POST['ss']}%";
and
$sysName = $_POST['ss'] . '%';
if(isset($_POST['ss'])) {
$sysName = $_POST['ss'] . '%';
if(strlen($sysName) >0) {
$qry = mysqli_stmt_prepare($link, "SELECT * FROM tblSchools WHERE systemName LIKE ?");
mysqli_stmt_bind_param($qry,'s',$sysName);
mysqli_stmt_execute($qry);
$result = mysqli_stmt_get_result($qry);
}
}
If $_POST['ss'] is populated with the word sys and there exists a systemName in tblSchools called 'system' then the result set should include the row information that pertains to the 'system' row. No matter what I put in there though the result always comes back null. My connection to the database is successful. I have tested with mysqli_query and just straight strings successfully, but when I switched to prepared statements on the LIKE clause it doesn't work. I've been beating my head against this problem for almost a full day now.
EDIT: In response to first answer Still doesn't work
$stmt = mysqli_stmt_init($link);
$sysName = "sys%";
if(strlen($sysName) >0) {
if(!mysqli_stmt_prepare($stmt, "SELECT * FROM tblSchools WHERE systemName LIKE ?")) {
echo "1";
exit;
} else {
if(mysqli_stmt_bind_param($stmt,'s',$sysName)) echo "2";
if(mysqli_stmt_execute($stmt)) echo "3";
$result = mysqli_stmt_fetch($stmt);
$row = mysqli_fetch_array($result);
var_dump($row);
echo "Hey";
}
}
Prints 2 and 3 not 1