I have created a search site which searches for all employees working in a org. Everything works perfectly fine except, just realized about this new problem.. if a user accidently types in a space like for an example for typing Joe they typed joe* (* is actually a  )... the user won't be able to see the space and when he/she clicks submit the search results ends in 0 match.
I am using post-gres as my back-end and I kinda new to php. The ideal solution I am looking for is some function which will be able to replace the space with nothing. probably a preg_replace .. I have got no idea. I have tried trimming but it does not work. Any help is highly appreciated.
Thank You
**************************************************
This is how my code looks now
Code: Select all
<?php
<?php
if(isset ($_POST['emp']))
{
print("<table width="700" align="center">
<tr>
<td>
<table width="600">
<font face="Arial, Helvetica, sans-serif" size=" ">
<strong><u>Search Results</u></strong></font></td>
</tr><tr><td> </td></tr>");
searchTheDatabase($_POST['emp']);
}
function searchTheDatabase($emp)
{
$query = "Select
employee.empid,employee.fname,
employee.lname, emp_info.phone,
department.name
FROM employee, department, emp_info
WHERE (lower(lname) Like lower('%$emp%')
OR lower(fname) Like lower('%$emp%'))
AND employee.empid = emp_info.empid
AND department.deptid = emp_info.deptid
ORDER by employee.fname";
$dbResult = pg_query($query);
if(!pg_numrows($dbResult))
{
print("<tr><td><font face="Arial, Helvetica, sans-serif" size="2">Sorry Nothing was found matched your query:
<strong><i>$emp</i></strong></font></td></tr>");
}
else
{
print("<tr><td colspan="3"><font face="Arial, Helvetica, sans-serif" size="2">
The following matches were found to your query:
<strong><i>$emp</i></strong></font></tr>
<tr><td colspan="3"> </td></tr>");
?>