I've got a problem, I can't see why the following code doesn't return any data, or at least any data that I can use. The $result doesn't produce an error but there's no data, the key I'm using definitely exists. <?php $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error()); //Select database mysql_select_db(DB_DATABASE, $conn) or die(mysql_error()); ?> <body> <?php include "../scripts/header.php"; ?> <?php $sql = "SELECT u.* FROM " . DB_DATABASE . "." . $table . " u WHERE u.ID=" . $uid . ""; $result = mysql_query($sql); if(!$result) { die('MySQL Error: ' . mysql_error()); exit; } $user = mysql_fetch_assoc($result); ?> <script language="javascript" type="text/javascript"> <?php echo 'alert("'. $user['username'] . '");'; ?> </script> snip... Code (markup): The answer is probably so simple, but I just can't see the solution.
Well, try simplifying everything at first, to see if you get a result: $sql = mysql_query("SELECT * FROM $table WHERE u.ID = '$uid'"); $result = mysql_numrows($sql); echo $result; This will show you if you get any results from the query
I've just discovered that mysql_fetch_assoc is case sensitive so $user['username'] is not the same as $user['Username']... Idiot language!
Be happy about it. Case-insensitivity is a major flaw which leads to countless bugs. This is programming we're talking about, not impressionist painting; precision is a virtue.