Matt Matt - 1 year ago 72
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download