Forum Moderators: coopster

Message Too Old, No Replies

Unable to search in database

it is only searching few entries

         

Silent Miracle

10:07 am on May 9, 2011 (gmt 0)

10+ Year Member



I have written a code for search . error i am getting is that it displays only search result of first 5 entries in a database whereas it is not showing the remaining entries in a database. Can anyone please tell me where i am doing mistake... Here is my code...
<head>
Search-RHMS
</head>
<body>
<form Name="theform" method= get>

<input type="text" name="User_Name" size= "10" maxlength="20"/>
<input type="submit" name="submit" value= "Search Patient"/>
</form>
<?php
error_reporting(E_ALL);
$db=mysql_connect('localhost','root','root');
if(!$db)
{
echo "Cannot connect to database";
}
$db_found=mysql_select_db('RHMS');

if (empty($_GET['User_Name']))
{
$UserName=False;
echo "Required field is empty";
}
else
{
$UserName=mysql_real_escape_string($_GET['User_Name']);
}

if ( $UserName)
{
$str="SELECT * FROM PAT_REG WHERE Name_User='".$UserName."'";
$result=mysql_query($str);
if(mysql_num_rows($result)==0)
{
echo "No record found";

}
else
{
$rows=mysql_fetch_array($result);
echo "<table border='1' cellspacing='2' cellpadding='2'>
<tr>
<th> ID</th>
<th> First Name</th>
<th> Last Name</th>
<th>City</th>
<th> Contact Num</th>
<th> User Name</th>
</tr>";

$kr= mysql_num_rows($result);
while($rows=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$rows['id']."</td> ";
echo "<td> ".$rows['Name_First']."</td> ";
echo "<td> ".$rows['Name_Last']."</td> ";
echo "<td> ".$rows['City']."</td> ";
echo "<td> ".$rows['Contact_num']."</td> ";
echo "<td> ".$rows['Name_User']."</td></br>";
echo "</tr>";
}
echo " </table>";
}

}
?>
</Body>

rocknbil

4:40 pm on May 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you sure there's more than five rows matching $User_Name? If there are any spaces or case DiFFerEnces it won't match on the equality operator =. Looks data related.