I want to search for the name in the database. However, I do not want to type the full name of the user. So I want to use the like function in SQL. When I use the like function, the result does not display anything. I still need to type full name of the user.
<form action="SearchStaff.php" method="post">
<fieldset style="background-color: #424242">
<table style="color: #141042">
<tr>
<td>STAFF NAME</td>
<td> <input type="text" name="USER_NAME" placeholder="STAFF NAME" style="text-
transform: uppercase;" size="40" > </td>
</tr>
</table>
<div><br>
<button type="submit" type="button" name="submit">Search Staff Name</button>
</div>
</fieldset>
</form>
<?php
if(isset($_POST["USER_NAME"])){
$B_title = strtoupper($_POST["USER_NAME"]);
//sql statement
include_once("DB_Connect.php");
$sql = "SELECT
TS_ID, TS_DATE, TS_DDATE, TS_HOUR, TRAINING_NAME,TRAINING_HOUR, USER_NAME
FROM
TRAINING_STATUS TS,
USER_INFO UI,
TRAINING B
WHERE
TS.TRAINING_ID = B.TRAINING_ID
AND
TS.USER_ID = UI.USER_ID
AND
UI.USER_NAME LIKE '$B_title%'
";
include("sql.php");
if($_SESSION['UserType'] == 'admin'){
print '<table style="width:100%">
<tr style="background-color:#6154FE">
<th>STAFF NAME</th>
<th>TRAINING NAME</th>
<th>ATTEND DATE</th>
<th>ATTEND TIME</th>
<th>TRAINING HOUR</th>
</tr>';
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
if($row['USER_NAME'] == $B_title && $B_title != null){
DisplayAdmin($row);
$loop = false;
}
}
}
}
?>
</div>
</center>
</body>