PHP/MySQL Select Statement Trouble Selecting Numbers!?

Having trouble getting this query to work right. So here is some details.

$username = mysql_real_escape_string($_COOKIE['username']);
$userID = $row['userID'];
$commentUserID = $row['commentUserID'];

$query = "SELECT userID FROM users WHERE username='$username'; // This statement works fine and returns the user ID number

$query2 = "SELECT * FROM comments WHERE commentUserID='$userID';

Now everything works fine except query2. If I replace '$userID' with say 83 it works fine but theres no point in that since it's not dynamic.

So basically I'm thinking the quotes are messing it up since your not supose to put numbers in quotes in a query I believe. So how do I get this to work?

commentUserID=83; // Works
commentUserID='$userID'; // Doesn't work but this is what I need to work.

Any ideas on how I get commentUserID='$userID'; to work right?
 
Back
Top