I'm using session variables in an SQL query that updates either wins or losses whenever called. I've looked over similar questions, but they are using mysql as opposed to mysqli. What is the correct manner for using php variables in a mysqli query? Here's what mine looks like:
$sqlQuery = "UPDATE users SET wins=wins+1 WHERE username == $_SESSION['username']";}
the resulting sql query should look like this:
UPDATE users SET wins=wins+1 WHERE username = 'user_name';
so we need to prepare it correctly:
$sql = sprintf(
"UPDATE users SET wins=wins+1 WHERE username = '%s';",
$_SESSION['username']
);
but please, use a proper database connector (PDO, mysqli) and escape the username.