Link to home
Start Free TrialLog in
Avatar of shampouya
shampouya

asked on

I'm having trouble using SELECT in mysql_query to retrieve one row of data

I have a mysql table called "Users" with four columns. I have a php file that starts out by defining a session variable below. But then later on, when I try to select the specific row in the table "where Username=$username", I get the error message "Unknown column 'bob' in 'where clause'." But if I replace that with "where Username='bob'" all of a sudden it works. Am I not allowed to use a php variable like $username in my "where" search?

<?php
session_start();
$username = $_SESSION['username'];
?>


$result = mysql_query("SELECT * FROM Users WHERE Username=$username") or die(mysql_error());
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shampouya
shampouya

ASKER

ahh, silly mistake, thanks!
You're welcome!