search based on 2 criteria (search-name-job.php)

This PHP script is used to cater search if two criteria are used. The first criteria is the employee’s FULLNAME and the second one is the employee’s JOB. The form will receive the values, and the SQL is customized based on the user’s input.

<title> Search for employee's name</title>
<form method="get" action="">
Search for employee's name<br>
Enter a name <input type="text" name="txtname"><br>
Enter the job <input type="text" name="txtjob"><br>
<input type="submit" value="Search">
/*database connection information
database server location=localhost
database username=root
password to username=NULL
database name=mycompanyhr
    echo "Connection succeed!!!<br>";
    echo "Connection fail!!!<br>";
//extract the name and job from the form
/*develop the SQL command with condition
FULLNAME and JOB based on the value in the form*/
$query="select *
        from employee
  where FULLNAME LIKE '%$employeename%' 
  and JOB LIKE '%$job%'";
//execute the SQL command
  //if SQL command fail, display the SQL errors
  echo ("Query cannot be executed!<br>");
  echo ("SQL Error : ".mysqli_error($db));
//if NO record found
  echo "No record found...";
//if records found, display in table
<table border="1"> 
    <td>Employee Number</td>
         echo (" <tr><td>".$rekod['EMPNO']."</td>");
         echo (" <td> ".$rekod['FULLNAME']."</td>");
         echo (" <td> ".$rekod['DEPT']."</td>");
         echo (" <td> ".$rekod['PHONENO']."</td>");
         echo (" <td> ".$rekod['JOB']."</td></tr>");
}//end else available records



Popular Posts