Selfish Posted August 10, 2009 Share Posted August 10, 2009 Well, I'm a beginner at coding, and I wan't a seach thing. When I say that, I wan't something that when you type in their username, it goes to their profile.I was wondering if anybody could code me one, thanks.Also, if you do, it'll be going to my RPG which can be found here.Thanks, Selfish. Link to comment Share on other sites More sharing options...
Synook Posted August 10, 2009 Share Posted August 10, 2009 Something like: <form action="search.php" method="get"><input type="text" name="username" /></form> $username = mysql_real_escape_string($_GET['username']);$id = implode(mysql_fetch_assoc(mysql_query("SELECT id FROM users WHERE username='$username'")));header("location:/forums/PokemonAtticRPG/profile.php?id=$id"); You just need to get the ID from the username entered and redirect - no "searching" necessary. Link to comment Share on other sites More sharing options...
Selfish Posted August 11, 2009 Author Share Posted August 11, 2009 Something like:<form action="search.php" method="get"><input type="text" name="username" /></form> $username = mysql_real_escape_string($_GET['username']);$id = implode(mysql_fetch_assoc(mysql_query("SELECT id FROM users WHERE username='$username'")));header("location:/forums/PokemonAtticRPG/profile.php?id=$id"); You just need to get the ID from the username entered and redirect - no "searching" necessary. Thanks you so much, but this happened: http://www.punbb-hosting.com/forums/Pokemo.../page.php?id=12 Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted August 11, 2009 Share Posted August 11, 2009 Assuming that each user has a unique username, you can do this: <form action="search.php" method="get"><div> <input type="text" name="username"> <button type="submit">Search</button> </div></form> <?php(string)$username = mysql_real_escape_string($_GET['username']);$con = mysql_connect("localhost", "database_user", "database_password");if(!mysql_select_db("database_name", $con)) { die("Error."); }$q = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");if(is_resource($q)) { (array)$user = mysql_fetch_assoc($q)); echo "<h1>{$user["username"]}</h1>"; // print out more details about the user here}else { die("Error: ".mysql_error());}?> Link to comment Share on other sites More sharing options...
Selfish Posted August 12, 2009 Author Share Posted August 12, 2009 It doesn't go to their profile, it just goes to the search link. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.