Create a php file based on this table. If the search keyword is "*", the program should display all employees in the table.   Your IP: $ip\n"; $IPv4 = explode(".", $ip); if (($IPv4[0] == '10') || ($IPv4[0] == '131' && $IPv4[1] == '125')) {     echo "You are from Kean University."; } else {     echo "You are NOT from Kean University."; } $keyword = isset($_POST["keyword"]) ? $_POST["keyword"] : ''; $conn = mysqli_connect($servername, $username, $password, $dbname); if (!$conn) {     die("Connection failed: " . mysqli_connect_error()); } if ($keyword === '*') {     $query = "SELECT * FROM EMPLOYEE";     $result = mysqli_query($conn, $query);     if ($result) {         $employeeCount = mysqli_num_rows($result);         echo "There are $employeeCount employee(s) in the database.";         if ($employeeCount > 0) {             displayEmployeeTable($result);         } else {             echo "No records found in the database.";         }         mysqli_free_result($result);     } else {         echo "Something went wrong with the SQL query: " . mysqli_error($conn);     } } else {     $query = "SELECT * FROM EMPLOYEE WHERE Address LIKE '%$keyword%'";     $result = mysqli_query($conn, $query);     $employeeCount = mysqli_num_rows($result);     echo "There are $employeeCount employee(s) in the database that the address contains the search keyword '$keyword'."; }   $result = mysqli_query($conn, $query); if ($result) {     if ($keyword === '*' || mysqli_num_rows($result) > 0) {         $totalSalary = 0;         $employeeCount = 0;         echo "                                     ID                     Login                     Password                     Name                     Role                     Gender                     Salary                     Address                 ";         while ($row = mysqli_fetch_assoc($result)) {             $employeeCount++;             $genderClass = ($row["gender"] == 'F') ? "red" : "blue";             echo "                     " . $row["employee_id"] . "                     " . $row["login"] . "                     " . $row["password"] . "                     " . $row["name"] . "                     " . $row["role"] . "                     " . $row["gender"] . "";             if (is_null($row["salary"])) {                 echo " NULL ";             } else {                 echo "" . $row["salary"] . "";                 $totalSalary += $row["salary"];             }             echo "" . $row["Address"] . "                   ";         }         echo "";         if ($keyword !== '*') {             $averageSalary = ($employeeCount > 0) ? $totalSalary / $employeeCount : 0;             echo "Average salary: $averageSalary";         }     } else {         echo "No result found for the keyword $keyword";     }     mysqli_free_result($result); } else {     echo "Something wrong with the SQL query: " . mysqli_error($conn); } mysqli_close($conn);

Fundamentals of Information Systems
8th Edition
ISBN:9781305082168
Author:Ralph Stair, George Reynolds
Publisher:Ralph Stair, George Reynolds
Chapter4: Telecommunications And Networks
Section: Chapter Questions
Problem 5SAT
icon
Related questions
Question

Create a php file based on this table. If the search keyword is "*", the program should display all employees in the table.  

<?php
include "dbconfig.php";

$ip = $_SERVER['REMOTE_ADDR'];
echo "<br>Your IP: $ip\n";
$IPv4 = explode(".", $ip);

if (($IPv4[0] == '10') || ($IPv4[0] == '131' && $IPv4[1] == '125')) {
    echo "<br>You are from Kean University.";
} else {
    echo "<br>You are NOT from Kean University.";
}

$keyword = isset($_POST["keyword"]) ? $_POST["keyword"] : '';


$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

if ($keyword === '*') {
    $query = "SELECT * FROM EMPLOYEE";
    $result = mysqli_query($conn, $query);

    if ($result) {
        $employeeCount = mysqli_num_rows($result);
        echo "<p>There are $employeeCount employee(s) in the database.</p>";

        if ($employeeCount > 0) {
            displayEmployeeTable($result);
        } else {
            echo "<br>No records found in the database.";
        }

        mysqli_free_result($result);
    } else {
        echo "<br>Something went wrong with the SQL query: " . mysqli_error($conn);
    }
} else {
    $query = "SELECT * FROM EMPLOYEE WHERE Address LIKE '%$keyword%'";
    $result = mysqli_query($conn, $query);
    $employeeCount = mysqli_num_rows($result);
    echo "<p>There are $employeeCount employee(s) in the database that the address contains the search keyword '$keyword'.</p>";
}

 

$result = mysqli_query($conn, $query);
if ($result) {
    if ($keyword === '*' || mysqli_num_rows($result) > 0) {
        $totalSalary = 0;
        $employeeCount = 0;
        echo "<table border='1'>
                <tr>
                    <th>ID</th>
                    <th>Login</th>
                    <th>Password</th>
                    <th>Name</th>
                    <th>Role</th>
                    <th>Gender</th>
                    <th>Salary</th>
                    <th>Address</th>
                </tr>";

        while ($row = mysqli_fetch_assoc($result)) {
            $employeeCount++;
            $genderClass = ($row["gender"] == 'F') ? "red" : "blue";

            echo "<tr>
                    <td>" . $row["employee_id"] . "</td>
                    <td>" . $row["login"] . "</td>
                    <td>" . $row["password"] . "</td>
                    <td>" . $row["name"] . "</td>
                    <td>" . $row["role"] . "</td>
                    <td><font color='$genderClass'>" . $row["gender"] . "</font></td>";

            if (is_null($row["salary"])) {
                echo "<td><font color='red'> NULL </font></td>";
            } else {
                echo "<td>" . $row["salary"] . "</td>";
                $totalSalary += $row["salary"];
            }

            echo "<td>" . $row["Address"] . "</td>
                  </tr>";
        }

        echo "</table>";

        if ($keyword !== '*') {
            $averageSalary = ($employeeCount > 0) ? $totalSalary / $employeeCount : 0;
            echo "<p>Average salary: $averageSalary</p>";
        }
    } else {
        echo "<br><br>No result found for the keyword <b>$keyword</b>";
    }

    mysqli_free_result($result);
} else {
    echo "<br>Something wrong with the SQL query: " . mysqli_error($conn);
}

mysqli_close($conn);

Your IP: 67.85.124.101
You are NOT from Kean Unversity.
There are 6 employee(s) in the database.
ID Login Password
Name
1 tiger xyz123
Victor Smith S
2 panda xyz333
John Lee E
5
Austin 613d3b9c91 Austin test S
6
fish
New test
E
7 bear
Tester 2019 E
8 lion 222
my Test
111
abc123
Average salary: 3100.0
Role Gender Salary Address
2500
M
M
F
M
F
S M
1000 Morris Ave., Union, NJ 07083
5000
133 Main St., Austin, TX
6000 71 Central Ave., Newark, NJ 07188
NULL 460 4th Ave., New York, N 101
1000 100 Texas Rd, Edison, NJ 07711
1000 100 Main Rd, Edison, NJ 07711
Transcribed Image Text:Your IP: 67.85.124.101 You are NOT from Kean Unversity. There are 6 employee(s) in the database. ID Login Password Name 1 tiger xyz123 Victor Smith S 2 panda xyz333 John Lee E 5 Austin 613d3b9c91 Austin test S 6 fish New test E 7 bear Tester 2019 E 8 lion 222 my Test 111 abc123 Average salary: 3100.0 Role Gender Salary Address 2500 M M F M F S M 1000 Morris Ave., Union, NJ 07083 5000 133 Main St., Austin, TX 6000 71 Central Ave., Newark, NJ 07188 NULL 460 4th Ave., New York, N 101 1000 100 Texas Rd, Edison, NJ 07711 1000 100 Main Rd, Edison, NJ 07711
Your IP: 118.232.23.22
You are NOT from Kean University
There are 4 employee(s) in the database that the address contains search keyword: t..
ID Login Password
Name
Role Gender Salary Address
John Lee E M
5000
133 Main St., Austin, TX
F
M
6000 71 Central Ave., Newark, NJ 07188
NULL 460 4th Ave., New York, N 101
1000 100 Texas Rd, Edison, NJ 07711
F
2 panda xyz333
5 Austin 613d3b9c91 Austin test S
6 fish
111
New test E
7 bear abc123
Tester 2019 E
Average salary: 4,000.0
Transcribed Image Text:Your IP: 118.232.23.22 You are NOT from Kean University There are 4 employee(s) in the database that the address contains search keyword: t.. ID Login Password Name Role Gender Salary Address John Lee E M 5000 133 Main St., Austin, TX F M 6000 71 Central Ave., Newark, NJ 07188 NULL 460 4th Ave., New York, N 101 1000 100 Texas Rd, Edison, NJ 07711 F 2 panda xyz333 5 Austin 613d3b9c91 Austin test S 6 fish 111 New test E 7 bear abc123 Tester 2019 E Average salary: 4,000.0
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Fundamentals of Information Systems
Fundamentals of Information Systems
Computer Science
ISBN:
9781305082168
Author:
Ralph Stair, George Reynolds
Publisher:
Cengage Learning