subtext Posted May 14, 2005 Report Share Posted May 14, 2005 OK, so if a user is logged in it's simple enough to get their username by checking $currentuser. Pretty much every page makes that obvious. But what if I want to display their real name and email address. Is there a concise (and secure) way of doing this? Quote Link to comment Share on other sites More sharing options...
subtext Posted May 14, 2005 Author Report Share Posted May 14, 2005 Hmm, figured this out myself I think. Not sure how secure or robust the code is. Any suggestions? <?php // Ensures 'Photos & Histories for Ancestors of [person]' link automatically links to details // of logged in user. (Assumes Individual ID (Ix) is declared in user description field. ) if ($currentuser) { $query = "SELECT realname FROM $users_table WHERE username = "$currentuser""; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row = mysql_fetch_assoc($result); $user_realname = $row["realname"]; if ( $currentuserdesc == "Administrator" ){ $user_record = "I1"; $user_tree = "defaulttree"; } else { $user_record = "$currentuserdesc"; $user_tree = "$assignedtree"; } mysql_free_result($result); echo "<li><a href="/extrastree.php?personID=$user_record&tree=$user_tree" class="lightlink">Photos & Histories<br>for Ancestors of<br>$user_realname</a></li>"; } ?> I thought I'd post the code because I figured others might find this function quite useful. Quote Link to comment Share on other sites More sharing options...
stizzed Posted March 16, 2006 Report Share Posted March 16, 2006 Hmm, figured this out myself I think. Not sure how secure or robust the code is. Any suggestions?<?php // Ensures 'Photos & Histories for Ancestors of [person]' link automatically links to details // of logged in user. (Assumes Individual ID (Ix) is declared in user description field. )if ($currentuser) { $query = "SELECT realname FROM $users_table WHERE username = "$currentuser""; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row = mysql_fetch_assoc($result); $user_realname = $row["realname"]; if ( $currentuserdesc == "Administrator" ){ $user_record = "I1"; $user_tree = "defaulttree"; } else { $user_record = "$currentuserdesc"; $user_tree = "$assignedtree"; } mysql_free_result($result); echo "<li><a href="/extrastree.php?personID=$user_record&tree=$user_tree" class="lightlink">Photos & Histories<br>for Ancestors of<br>$user_realname</a></li>"; }?>I thought I'd post the code because I figured others might find this function quite useful.I tried to add this code to index.php (Somehow I knew it would not be easy) and I get this error:Parse error: syntax error, unexpected T_VARIABLE in c:\Inetpub\wwwroot\index.php on line 155The line in question is:$query = "SELECT realname FROM $users_table WHERE username = "$currentuser"";Any Ideas? Quote Link to comment Share on other sites More sharing options...
gvdm Posted March 17, 2006 Report Share Posted March 17, 2006 I tried to add this code to index.php (Somehow I knew it would not be easy) and I get this error:Parse error: syntax error, unexpected T_VARIABLE in c:\Inetpub\wwwroot\index.php on line 155The line in question is:$query = "SELECT realname FROM $users_table WHERE username = "$currentuser"";Any Ideas?extra quote mark just before the semi colon Quote Link to comment Share on other sites More sharing options...
gvdm Posted March 17, 2006 Report Share Posted March 17, 2006 extra quote mark just before the semi colonsorry, It needs to be there Quote Link to comment Share on other sites More sharing options...
stizzed Posted March 17, 2006 Report Share Posted March 17, 2006 sorry, It needs to be thereHAHAHA! That didn't help ~much~. <smyle> Quote Link to comment Share on other sites More sharing options...
rdmorss Posted March 17, 2006 Report Share Posted March 17, 2006 T_VARIABLE errors, in my experience, are often caused by a missing quote or semicolon or parenthesis somewhere BEFORE the line given in the error message. It doesn't kill the parser until that line, when it gives up and reports where it was when it bailed out. Quote Link to comment Share on other sites More sharing options...
jhuber Posted March 20, 2006 Report Share Posted March 20, 2006 Even if you fix your php code, the underlying logic seems to be faulty. The ID number for each individual is not linked in any way to *anything* in the users table. So you can't pull a rabbit out of that hat because the rabbit isn't there.The following code is yours with a few corrections. It works, but the result can't be what you wanted.<?php // Ensures 'Photos & Histories for Ancestors of [person]' link automatically links to details // of logged in user. (Assumes Individual ID (Ix) is declared in user description field. )if ($currentuser) { $query = "SELECT realname FROM $users_table WHERE username = \"$currentuser\""; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row = mysql_fetch_assoc($result); $user_realname = $row["realname"]; if ( $currentuserdesc == "Administrator" ){ $user_record = "I1"; $user_tree = "defaulttree"; } else { $user_record = "$currentuserdesc"; $user_tree = "$assignedtree"; } mysql_free_result($result); echo "<a href=\"extrastree.php?personID=$user_record&tree=$user_tree\">Photos & Histories<br>for Ancestors of<br>$user_realname</a>" ; }?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.