Matt Matt - 11 days ago 6
PHP Question

Adding session variable into MYSQL query using PHP

Im trying to pass two variables into a mysql query, and its getting stuck when passing the session variable in below:

$check = mysql_query("SELECT *
FROM Clients
WHERE Username = '$new_username'
AND Username != '$_SESSION['Username']'") or die(mysql_error());


Any tips? Thanks in advance.

Answer

It is because your single quotes '$_SESSION['Username']' have been ended by the value in the session. Changing this to '" . $_SESSION['Username'] . "' will solve the problem.

Comments