I am trying to add a record in a table based upon the UID of a member in my Drupal site. I am doing this with a form that is on each member's page. For this to work properly, I need to use the UID in the mysql query. This is being included in the page with a in a Drupal block.
If I use $uid = $user->uid;, it will be my UID as admin. I need for it to populate with the UID of of the member whose page I am currently viewing.
Here's a little snippet of my code:
mysql_query("INSERT INTO profile_values (fid, uid, value) VALUES ('99','$uid', '$newcompany')");
I need to define $uid and this will work perfectly! (this is Drupal Commons, if that makes a difference)
If you're on a user page then whatever the current URL is the underlying router path will be
user/%
, where%
is the user's ID.With this in mind you can use Drupal's
arg()
function to grab the parts of the URL split by the/
character, and thus the user ID:Bear in mind the
if
above will also match paths such asuser/%/edit
so if that's going to cause a problem just add&& is_null(arg(2))
to the conditions.