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.
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.
This will work but this is VERY, VERY BAD:
$check = mysql_query("
SELECT *
FROM Clients
WHERE Username = '$new_username'
AND Username != '{$_SESSION['Username']}'
") or die(mysql_error());
This too shall work and recommended way of doing it:
$check = mysql_query("
SELECT *
FROM Clients
WHERE Username = '" . mysql_real_escape_string($new_username) . "'
AND Username <> '" . mysql_real_escape_string($_SESSION['Username']) . "'
") or die(mysql_error());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With