When the user is logged in I am trying to find their information so I can display it to them, then I am going to allow them to update their information.
I keep getting an unknown column error, which is my session variable in the where clause but I am not sure why. The code below shows my query that I am using.
$query="SELECT * FROM users WHERE username = ". $_SESSION['login_user'];
Best way is to use a Prepared Statement
with a placeholder for the login
in your SQL and replace it with the value from the Session.
Another non-production-standard way is to enclose the login value in single quotes. Without the quotes, the SQL engine is thinking the login to be a column name.
如果您的列username
是键入的字符串,则应添加'
进行过滤,如下所示:
$query="SELECT * FROM users WHERE username = '". $_SESSION['login_user'] + "'";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.