sean04 Posted May 1, 2010 Share Posted May 1, 2010 Hey guys, Could someone take a look and please let me know whats wrong? //make picture the profile picture if(isset($_GET['Search'])) { $searchby = $_POST['SearchBy']; $userID = htmlspecialchars(mysql_real_escape_string($_POST['ID'])); if($searchby == "UserID"){ $searchUserID = mysql_query("SELECT * FROM userinfo WHERE User_ID LIKE '".$userID."%'") or die(mysql_error()); $seachUserCount = mysql_fetch_array($searchUserID); if($seachUserCount == 0){ echo"No Users Found"; } else { while ($UserSearch = mysql_fetch_array($searchUserID)) { echo "$UserSearch[user_ID]"; } } } } searchby is the name of a few radio buttons Link to comment https://forums.phpfreaks.com/topic/200367-search/ Share on other sites More sharing options...
TeddyKiller Posted May 1, 2010 Share Posted May 1, 2010 Not too sure on the problem, you haven't told us that much. Although.. if($searchby == "UserID"){ Whats this? EDIT: This may be useful to you. You are checking the numbero f rows via mysql_fetch_array() When it should be mysql_num_rows() <?php if(isset($_GET['Search'])) { $searchby = $_POST['SearchBy']; $userID = htmlspecialchars(mysql_real_escape_string($_POST['ID'])); if($searchby == "UserID"){ $searchUserID = mysql_query("SELECT * FROM userinfo WHERE User_ID LIKE '".$userID."%'") or die(mysql_error()); if(mysql_num_rows($searchUserID) == 0){ echo"No Users Found"; } else { while ($UserSearch = mysql_fetch_array($searchUserID)) { echo "$UserSearch[user_ID]"; } } } } ?> Link to comment https://forums.phpfreaks.com/topic/200367-search/#findComment-1051511 Share on other sites More sharing options...
sean04 Posted May 1, 2010 Author Share Posted May 1, 2010 Sorry heres my form <form action='?SearchUser' method='post'> Search user by:<p/> <input type = 'Radio' Name ='SearchBy' value='UserID'>User ID<br/> <input type = 'Radio' Name ='SearchBy' value='ScreenName'>Screen Name<br/> <input type = 'Radio' Name ='SearchBy' value='Email'>Email<br/> <p/> <input id='ID' type='text' name='ID' /><p/> <input type='submit' name='submit' value='Search'/> </form> When I type a user ID in the ID text box and search, the user wont show up Link to comment https://forums.phpfreaks.com/topic/200367-search/#findComment-1051513 Share on other sites More sharing options...
TeddyKiller Posted May 1, 2010 Share Posted May 1, 2010 Ok. Use my code above.. change if(isset($_GET['Search'])) { to if(isset($_POST['submit'])) { Link to comment https://forums.phpfreaks.com/topic/200367-search/#findComment-1051518 Share on other sites More sharing options...
sean04 Posted May 1, 2010 Author Share Posted May 1, 2010 Thanks for the reply! I want it so if I type in the user id of 7 in the textbox, my username will show up because I'm user 7. Likewise if i chose screenName as the radio button selection and typed in "Sean", My name would show up along with anyone else who's name is like "Sean". the problem is is that nothing is showing up when i press submit. Link to comment https://forums.phpfreaks.com/topic/200367-search/#findComment-1051525 Share on other sites More sharing options...
sean04 Posted May 1, 2010 Author Share Posted May 1, 2010 its picking up there there is a user 7 but it wont display. the reason i know this is because i type in 7 and the message"No Users Found" doesn't come up. Link to comment https://forums.phpfreaks.com/topic/200367-search/#findComment-1051543 Share on other sites More sharing options...
TeddyKiller Posted May 1, 2010 Share Posted May 1, 2010 Whats your current code? Link to comment https://forums.phpfreaks.com/topic/200367-search/#findComment-1051547 Share on other sites More sharing options...
sean04 Posted May 1, 2010 Author Share Posted May 1, 2010 everything i posted above Link to comment https://forums.phpfreaks.com/topic/200367-search/#findComment-1051566 Share on other sites More sharing options...
TeddyKiller Posted May 1, 2010 Share Posted May 1, 2010 There is no reason for my code not to work at all. Few minor changes, I dont think it'd of made a difference. <?php if(isset($_POST['submit'])) { $searchby = $_POST['SearchBy']; $userID = htmlspecialchars(mysql_real_escape_string($_POST['ID'])); if($searchby == "UserID"){ $searchUserID = mysql_query("SELECT * FROM userinfo WHERE User_ID LIKE '".$userID."%'") or die(mysql_error()); if(mysql_num_rows($searchUserID) == 0){ echo 'No Users Found'; } else { while ($UserSearch = mysql_fetch_assoc($searchUserID)) { echo $UserSearch['User_ID']; } } } } ?> Link to comment https://forums.phpfreaks.com/topic/200367-search/#findComment-1051584 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.