Create a web page to retrieve personal details of an employee when his first name or last name is given as an input using a web page. First create an Employee table inside company_A database which contains the following fields.IDFirst nameLast nameDate of BirthDesignationStart DateSalaryBranch
Question
Create a web page to retrieve personal details of an employee when his first name or last name is given as an input using a web page. First create an Employee table inside company_A database which contains the following fields.IDFirst nameLast nameDate of BirthDesignationStart DateSalaryBranch
Solution
Sure, here is a step-by-step guide on how to create a web page to retrieve personal details of an employee using HTML, PHP, and MySQL.
Step 1: Create the Employee table in the company_A database.
CREATE DATABASE company_A;
USE company_A;
CREATE TABLE Employee (
ID INT AUTO_INCREMENT,
First_name VARCHAR(50),
Last_name VARCHAR(50),
Date_of_Birth DATE,
Designation VARCHAR(50),
Start_Date DATE,
Salary DECIMAL(10,2),
Branch VARCHAR(50),
PRIMARY KEY(ID)
);
Step 2: Create a HTML form to take the first name or last name as input.
<!DOCTYPE html>
<html>
<body>
<h2>Employee Details Form</h2>
<form action="get_employee_details.php" method="post">
First name:<br>
<input type="text" name="first_name">
<br>
Last name:<br>
<input type="text" name="last_name">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Step 3: Create a PHP script to retrieve the employee details from the database.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "company_A";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$sql = "SELECT * FROM Employee WHERE First_name='$first_name' OR Last_name='$last_name'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "ID: " . $row["ID"]. " - Name: " . $row["First_name"]. " " . $row["Last_name"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
Please replace "localhost", "username", and "password" with your actual database host, username, and password.
This is a basic example. In a real-world application, you should use prepared statements to prevent SQL injection attacks. Also, you should not echo the database errors to the user, it's a bad practice. Instead, you should handle errors gracefully and log them.
Similar Questions
Create Table Employee with attributes firstName,LastName,SSN,Address,Salary,Birthday,Sex,SupervisorSSN,DepartmentNo
Write a PHP program to connect to a database and create a database with employee table.
You have a database with a customers table. Here is a partial listing of the records:First_NameLast_NameMichelleSenseAlexisRodriguezFloraSatoYou also have a table of employees. Here is a partial listing of the records:First_NameLast_NameSamuelClementineAlexisRodriguezJabariReddyYou want to create a query that will not return “Alexis Rodriguez” as part of the results. You begin typing your query:SELECT First_Name, Last_Name FROM customers________SELECT First_Name, Last_Name FROM employeesWhat should you type in the blank space between the two queries? (Please type your answer all in upper case. Example: SELECT)
The names of each employee in a database would most likely be stored where?In rowsIn every field In columnsAs separate tables
Which of the following query is correct to fetch all the employee details from the employee tableselect * from employee;extract name from employee;
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.