...

View Full Version : Typing in ID showing Username



masterofollies
11-27-2007, 01:36 AM
Hi, I am making a friends list on my website, and when you put in a friends ID number, it adds it to the list. But (of course) it shows the ID. I would like it to change the ID to the persons name.

Here is some of what I have coded, maybe someone can figure out how to check users to match ID?


if (isset($_POST["submit"])) {
$id=$_POST['id'];
$id=strip_tags($id);

if ($userrow["friend1"] == "None") {
$page = "<table width='100%'><tr><td class='title'>Add New Friends</td></tr></table>";
$page .= "<center><font color=lightgray><b>Fayt:</b> You have added
Player ID $id to your friends list.<br /><br />";
$page .= "You can return to <a href=\"index.php\">Town</a></font></center><p>";
$updatequery = doquery("UPDATE {{table}} SET friend1='$id' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
}


else {
$updatequery = doquery("UPDATE {{table}} SET location='Friends List' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
$title = "Friends List";
$page = "<table width='100%' border='1'><tr><td class='title'>Add New Friends</td></tr></table><p>";
$page .= "<center><font color=lightgray><b>Welcome to your friends list!</b><br /><br />";
$page .= "You currently have the following friends:</font><br /><br />";
$page .= "<font color=white><b>Friend 1:</b> ".$userrow["friend1"]."</font><br />";

$page .= "<form action=\"friends.php?do=main\" method=\"post\">";
$page .= "<input type=\"text\" name=\"id\" value=\"ID\" /> <input type=\"submit\" name=\"submit\" value=\"Add Friend\" /></form><br /><br /><br />";

display($page, $title);

}

Inigoesdr
11-27-2007, 03:15 AM
SELECT `username` FROM `users` WHERE `id` = $id

masterofollies
11-27-2007, 05:08 AM
So make it like this?


$query = doquery("SELECT username FROM {{table}} WHERE id='$id' LIMIT 1", "users");

and how would I call that? Meaning how do I get the username to come up in the friend 1 spot instead of a number?

Inigoesdr
11-27-2007, 05:24 AM
So make it like this?
Yep.

and how would I call that? Meaning how do I get the username to come up in the friend 1 spot instead of a number?
I have no idea.. you're using a non-standard function for the query. Normally you would use mysql_query() to execute the query, and mysql_result() or mysql_fetch_*() to get the row's fields.

masterofollies
11-27-2007, 02:15 PM
Hmm this is going to take alot of thinking to figure out...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum