query not returnung rows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Guys fallowing is  code for search form. Here what the problem is
the query
SELECT * FROM bulk_register WHERE ".$field." LIKE'%".$find."%'";
not returning any Result.
plz tell me whre the error is.


<?php
if(isset($_POST['search']))
{
 echo $_POST['field'];
 $find=$_POST['find'];
 $field=$_POST['field'];
//This is only displayed if they have submitted the form
if (isset($_POST['searching']))
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("bulksms") or die(mysql_error());

// We preform a bit of filtering
//$find = strtoupper($find);
//$find = strip_tags($find);
$find = trim ($find);
echo "find is".$find."<br>";
//Now we search for our search term, in the field the user specified
$query="SELECT * FROM bulk_register WHERE ".$field." LIKE'%".$find."%'";
echo "query is".$query;
$data = mysql_query($query);

//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['firstname'];
echo " ";
echo $result['lastname'];
echo "<br>";
echo $result['mobile'];
echo "<br>";
echo "<br>";
}

//This counts the number or results - and if there wasn't any it gives
them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}

}
?>






<h2>Search</h2>
<form name="search" method="post" action="searchform.php">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="firstname">First Name</option>
<Option VALUE="lastname">Last Name</option>
<Option VALUE="mobile">Mobile</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux