사용자가 사원 이름과 성을 입력 할 수있는 양식을 만들었습니다. 제출하는 사용자가 항목이 employees 테이블의 first_name 열과 같은 직원 데이터베이스에서 모든 항목을 선택해야합니다. 그렇게하면 페이지에 표시되지 않으므로 찾을 수없는 잘못된 것이 있어야합니다.사용자 입력을 기반으로 한 데이터베이스 결과 표시
<!doctype html>
<html lang="en">
<head>
<link href="employeeStyles.css" rel="stylesheet">
<title>Employee Search</title>
</head>
<body>
<div id="employeeArea">
<h1>Employee Search Results</h1>
<?php
$firstName = $_GET['firstName'];
$lastName = $_GET['lastName'];
$resultsNumber = $_GET['resultsNumber'];
@ $db = new mysqli('localhost','root','','employees');
$firstName = $db->real_escape_string($firstName);
$lastName = $db->real_escape_string($lastName);
$resultsNumber = $db->real_escape_string($resultsNumber);
if (mysqli_connect_errno()){
echo 'Error: Could not connect to the database. Please try again later. </body></html>';
exit;
}
$query = "SELECT * FROM employees WHERE first_name LIKE .$firstName.'%'";
$result = $db->query($query);
$numResults = $result->num_rows;
echo 'Number of results found '.$numResults;
for ($i=0; $i<$result; $i++){
$row = $result->fetch_assoc();
echo $row ['first_name']."<br>";
echo $row ['last_name']."<br>";
echo $row ['emp_no']."<br>";
echo $row ['hire_date']."<br>";
echo $row ['birth_date']."<br>";
echo $row ['gender']."<br>";
}
$db->close();
?>
</div>
</body>
'LIKE $ firstName을 '%'가'구문 오류와'mysqli_error ($의 dB)이다'그것에 대해 말했을 것이다. –