-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_emp_no.php
executable file
·46 lines (36 loc) · 1.34 KB
/
search_emp_no.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
//access credentials fils
include 'credentials.php';
//this is the php object oriented style of creating a mysql connection
$conn = new mysqli($servername, $username, $password, $dbname);
//check for connection success
if ($conn->connect_error) {
die("MySQL Connection Failed: " . $conn->connect_error);
}
//pull the attribute that was passed with the html form GET request and put into a local variable.
$emp_no = $_GET["emp_no"];
//create the SQL select statement, notice the funky string concat at the end to variablize the query
//based on using the GET attribute
$sql = "SELECT * FROM employees where emp_no = '".$emp_no."'";
//echo $sql; //troubleshooting statement if needed
//put the resultset into a variable
$result = $conn->query($sql);
//Iterate through the rows
if ($result->num_rows > 0){
//print rows
while($row = $result->fetch_assoc()){
echo 'First Name: ' . $row["first_name"]. ';Last Name: ' . $row["last_name"];
// set response code - 200 OK
http_response_code(200);
}
} else {
http_response_code(404);
echo "No Records Found";
}
//close db connect
$conn->close();
//always close the DB connections, don't leave 'em hanging
?>