I have a problem using LIKE with PHP variables. I would like to select, based on a username, what matches the username in the DB. Here is my code:
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "1234";
$dbname = "coffeecorner";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$user = $_SESSION['username'];
$sql = "select username ";
$sql .= "from add_reservation";
$sql .= "where username like" . $user;
$result = mysqli_query($connection, $sql);
if(!$result)
{
die("database query fail!" . mysqli_error($connection));
}
Error
database query fail! 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 'likeipin' at line 1
Any help would be appreciated!

LIKEhas to be a string, so it needs quotes around it. But you should learn to use prepared statements withmysqli_stmt_bind_paraminstead of substituting variables into the SQL.LIKE? If you're looking for a specific username, it should be=, notLIKE. You useLIKEwhen you're trying to match a pattern with wildcards in it.LIKEclause should be similar to this:where username like '%Mond%'... currently, you are missing a space. And please use prepared statements here.