I have a table named "df_users_permissions" and each user has a row which includes information such as their name, etc. I am trying to find the "homefolder" for the current user. Each user is given a unique ID and each user has a different home folder, so I was thinking I could find the user's home folder by locating the row which matches the user's ID then seeing what the value for "homefolder" is in that row. Here is what I have, but it's not working: $homefolder = mysql_query("SELECT homefolder FROM df_users_permissions WHERE id= $docsuserid"); PHP: Could someone give me a hand with this? Much appreciated!
The actual query looks correct, but if you take a look at the documentation for mysql_query you'll see that it returns a resource, which you then feed into mysql_fetch_assoc, for example. So: $res = mysql_query( "SELECT..." ); $fields = mysql_fetch_assoc( $res ); $homefolder = $fields[ 'homefolder' ]; PHP:
Your SQL looks correct but you are not referencing the query correctly. http://php.net/manual/en/function.mysql-query.php Note the return value - (assuming success) it returns a resource. You need to then process the result set in that resource using either of these; http://www.php.net/manual/en/function.mysql-fetch-array.php http://php.net/manual/en/function.mysql-fetch-assoc.php I.E Something like; $sql = mysql_query("SELECT homefolder FROM df_users_permissions WHERE id= $docsuserid"); if($sql === FALSE) die(mysql_error()); else { # Its only 1 record thats being returned, so no need to use a loop here # You might want to check 1 record was returned using mysql_num_rows too.... $results = mysql_fetch_array($sql); print $results[0]; } PHP: