This is the code i'm trying to get working $user_id = $_SESSION['id']; $query = " SELECT * FROM users WHERE id = $user_id "; $result = mysql_query($query) or die('Error, query failed'); while($row = mysql_fetch_array($result)) { echo '<p>Welcome ' . $row['name'] . '.</p>'; } PHP: Any idea why it's not? All that comes up when it's run is "Welcome ." I have tried putting echo $user_id; after it gets the id from the session, that gets it correctly. So basicly the error is somewhere in the query but I really have no idea where or why, i'm using variables like this in other queries on the site and they work Anyway, any help would be great! Thanks, TS
try session_start(); $user_id = $_SESSION['id']; // be sure to clean / check variables $query = "SELECT * FROM `users` WHERE `id` = '".$user_id."' LIMIT 1"; $result = mysql_query($query) or die('Error, query failed. '.mysql_error()); $RS = array(); while($row = mysql_fetch_assoc($result)) { $RS[] = $row; } echo '<pre>'; print_r($RS); echo '</pre>'; PHP: to see what's in there..