Jump to content

Search


sean04

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.