Jump to content

problem with a member search


codenature

Recommended Posts

I have a problem with database search for a member. I am pretty sure my sql is correct. It must be my if statements.

 

Upon submitting the search for a member, even if there is not a match, the link appears for the member that was entered into the search. I only want the link to show up if there is a match.

 

Thank you in advance.

 

<?php 

error_reporting(E_ALL);
require_once("./include/membersite_config.php");
//session_start();//FOR GETTING USER ONLINE SCRIPT

header("Cache-Control: nocache");
header("Expires: 0");



if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("login.php");
    exit;
}

$currentUser=$_SESSION['name_of_user']; // set current user name logged in to $currentUser to grab his profil DB data later.





if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("login.php");
    exit;
}

//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","100");

//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;

include 'memberHeader.php';




if (isset($_POST['submit']))	

{
$memberSearch=$_POST['memberSearch'];


mysql_connect(" ", " ", " ") or die(mysql_error());  // info left out
				mysql_select_db(" ") or die(mysql_error()) ;


				$sql = "SELECT username FROM users WHERE username='$memberSearch'";


						$result = mysql_query($sql);

						echo $result;

						if (!$result) {
							echo "no matching member found " . mysql_error();
							exit;
						}
					     if($result) {

						 echo "Your search result link: <a href='viewProfile.php?userPage=".$memberSearch."'>click here for result</a>";
}

////////////////////////////////MEMBER SEARCH FORM//////////////
















}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<p> </p><p> </p><p><? 	echo "<p>  </p><p></p><form id='form1' name='form' method='post' action=''>

Enter a member's name here to search <input type='text' name='memberSearch' id='memberSearch' />
  <input type='submit' name='submit' id='submit'/>
</form>"; ?> </p>
</body>
</html>

Link to comment
Share on other sites

<?php 
if (!$result) {
echo "no matching member found " . mysql_error();
exit;
}
if($result) {
echo "Your search result link: <a href='viewProfile.php?userPage=".$memberSearch."'>click here for result</a>";
}

 

You need to check for num_rows. Even if it returns 0 rows (which is what you're trying to catch) $result will still be true (or not false to be more accurate), which is why you're getting the link.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.