$search_query = mysqli_real_escape_string($conn, $_POST['this']);
$sql = "SELECT this FROM that WHERE this LIKE ' '%' + " .$search_query. " + '%' '";
This is what I have so far, is there something wrong with this syntax?
$search_query = mysqli_real_escape_string($conn, $_POST['this']);
$sql = "SELECT this FROM that WHERE this LIKE ' '%' + " .$search_query. " + '%' '";
This is what I have so far, is there something wrong with this syntax?
If you rewrite your query using prepared statements you won't have this type of issue. For example:
$sql = 'SELECT this FROM that WHERE this LIKE ?';
$stmt = $conn->prepare($sql);
$search_query = '%' . $_POST['this'] . '%';
$stmt->bind_param('s', $search_query);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo $row['this'];
}
Note get_result
is only available with the mysqlnd
driver, if you don't have that, replace the last 4 lines with
$stmt->bind_result($ths);
while ($stmt->fetch()) {
echo $ths;
}