Zoofu Posted August 22, 2009 Share Posted August 22, 2009 <?php function profile($uid, $link = FALSE){ $sql1 = "SELECT * FROM `users` WHERE `id`='".$uid."'"; $res1 = mysql_query($sql1) or die(mysql_error()); if(mysql_num_rows($res1) == 0){ return "Invalid User"; }else { $row1 = mysql_fetch_assoc($res); if(!$link){ return $row1['username']; }else { return $row1['username']; } } } echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"20%\">\n"; echo "<tr align=\"left\"><td class=\"forum_header\">".profile($row1['username'])."</a><br>UserID: ".$uid."</td></tr>\n"; echo "<br>\n"; echo "</table>\n"; ?> It's returning invalid users. If this script is wrong, please can someone tell me... I'm making a profile page, and I need it to show the users name. As in like, if the profile id is 2, it'll show User #2's name. Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/ Share on other sites More sharing options...
dreamwest Posted August 22, 2009 Share Posted August 22, 2009 Heres the error: $row1 = mysql_fetch_assoc($res); Should be $row1 = mysql_fetch_assoc($res1); Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903769 Share on other sites More sharing options...
ignace Posted August 22, 2009 Share Posted August 22, 2009 Don't just return "Invalid user" avoid typo's and use constants. define('PROFILE_ERR_INVALID_USER', 'invalid'); function profile($uid, $link = FALSE) { $sql1 = "SELECT * FROM `users` WHERE `id`='".$uid."'"; $res1 = mysql_query($sql1) or die(mysql_error()); if(mysql_num_rows($res1) == 0){ return PROFILE_ERR_INVALID_USER; } else { $row1 = mysql_fetch_assoc($res1); if (!$link) { return $row1['username']; } else { return $row1['username']; } } } Afterwards use: $response = profile(..); if (PROFILE_ERR_INVALID_USER !== $response) { Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903872 Share on other sites More sharing options...
Zoofu Posted August 22, 2009 Author Share Posted August 22, 2009 Okay, I think my script was pointless, what I wanna do... Is show the person's name. Let's say you're looking at http://zoofu.000space.com/index.php?act=profile&id=2 Which would be member 2's profile. How can I get it to show that users name? Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903882 Share on other sites More sharing options...
Zoofu Posted August 22, 2009 Author Share Posted August 22, 2009 Does anyone know how I would do that? O.o Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903887 Share on other sites More sharing options...
peter_anderson Posted August 22, 2009 Share Posted August 22, 2009 Try echo $row1['username']; To show the username. Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903898 Share on other sites More sharing options...
Zoofu Posted August 22, 2009 Author Share Posted August 22, 2009 Nope. Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903917 Share on other sites More sharing options...
Aravinthan Posted August 22, 2009 Share Posted August 22, 2009 Show us your table to see how you builded it... Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903922 Share on other sites More sharing options...
Zoofu Posted August 22, 2009 Author Share Posted August 22, 2009 Arav, just replace it with like `table` and stuff and I'll just edit it from there. Make up field >.> Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903926 Share on other sites More sharing options...
Aravinthan Posted August 22, 2009 Share Posted August 22, 2009 I will go simple to start. $username = $_POST['username']; // Get Username via a form $sql1 = "SELECT * FROM `users` WHERE `username`='$username' "; $res1 = mysql_query($sql1) or die(mysql_error()); if(mysql_num_rows($res1) == 0){ return PROFILE_ERR_INVALID_USER; } else { $row1 = mysql_fetch_assoc($res1); if (!$link) { return $row1['username']; } else { return $row1['username']; } } Try this. If it works we can go a bit more more deeper Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903930 Share on other sites More sharing options...
Zoofu Posted August 22, 2009 Author Share Posted August 22, 2009 There was no mysql error. Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903936 Share on other sites More sharing options...
Aravinthan Posted August 22, 2009 Share Posted August 22, 2009 Good, I have a question for previous code, Can you echo out $uid ? If it is empty, there is your problem. Link to comment https://forums.phpfreaks.com/topic/171376-whats-wrong-with-this-script/#findComment-903943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.