hi am trying to connect to sql server through php, search and display the results based on search string. following is the index.php
am successful in getting the results separately by writing query but not through this search form
Following is the search.php
<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(!$button)
echo "you didn't submit a keyword";
else
{
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
}
$serverName = "xxxx";
$connectionInfo = array( "Database"=>"xxxx", "UID"=>"xxxx", "PWD"=>"xxxx");
$conn = sqlsrv_connect( $serverName, $connectionInfo );
$Query = "SELECT employee_name FROM employees WHERE employee_name like '%".$search."%'";
$run = sqlsrv_query($conn,$Query);
$foundnum = sqlsrv_num_rows($run);
if ($foundnum==0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.";
else
{
echo "$foundnum results found !<p>";
while($row = SQLSRV_FETCH_ARRAY($run,SQLSRV_FETCH_ASSOC))
{
echo $row['Employee_name'];
}
sqlsrv_free_stmt($run);
}
}
?>