<form id="form1" name="form1" method="post" action="  <?php
include("connect.php");
require("search2.php");
$username = $_SESSION['email'];
?>
">
        <p>
          <input type="text" name="search" id="search" value=""/>
              <input type="submit" name="btnSearch" id="btnSearch" value="SEARCH" />
      </p></form>

search2.php

      <?php
include("connect.php");
$username = $_SESSION['email'];
$name=$_POST['search'];
$query = mysql_query ("Select * from confirm_members where email = '$name'");
if(mysql_num_rows($query)==0)
        die ("User not found");
    else
{   
 while ($row = mysql_fetch_array($query))
{
 $members = $row ['email'];
 $location = $row ['imagelocation'];
 echo "<img src ='$location' width='100' height='100'>"."<a href= 'friendprofile.php?MemberID=$members'>".$members;
  } 
}


$search = mysql_query ("Select * from friends where user1 = '$username' && user2 = '$name'  ");
if(mysql_num_rows($search)==0)
echo "</a>"."&nbsp"."&nbsp"."<a href='addfriend.php?MemberID=$members'>"."Add as friend"."</a>"."</p>";         
    else
    {
 while ($row = mysql_fetch_array($query))
{
 $username = $row ['user1'];
 $name = $row ['user2'];
 $stat = $row ['status'];
} 

}
?>

You did not show the message you got, so I'll guess $name=$_POST['search']; does not have a value set. The best way is to use the following construct:

$name = isset($_POST['search']) ? $_POST['search'] : '';

@pritaeas thank you for nyour reply.but when i did what you said it displays "User not found" even if i havent click the search button.what can i do?

Your query returns no records, or fails. To check failure do this:

$query = mysql_query ("Select * from confirm_members where email = '$name'") or die(mysql_error());

If it does not fail, check your data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.