Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating a php file that is supposed to update my employees table in my database called hr _ tracker. ` ` ` connect _ error

Creating a php file that is supposed to update my employees table in my database called hr_tracker. ```connect_error){
die("Connection failed: ". $conn->connect_error);
}
return $conn;
}
// Check if the form is submitted for updating the employees table
if ($_SERVER["REQUEST_METHOD"]== "POST"){
if (isset($_POST['update']) && isset($_POST['empID'])){
$conn = connectToDatabase(); // Connect to the database
$empID = $conn->real_escape_string($_POST['empID']);
$firstName = $conn->real_escape_string($_POST['firstName']);
$lastName = $conn->real_escape_string($_POST['lastName']);
$address = $conn->real_escape_string($_POST['address']);
$city = $conn->real_escape_string($_POST['city']);
$state = $conn->real_escape_string($_POST['state']);
$zipCode = $conn->real_escape_string($_POST['zipCode']);
$phoneNumber = $conn->real_escape_string($_POST['phoneNumber']);
$email = $conn->real_escape_string($_POST['email']);
$jobID = $conn->real_escape_string($_POST['jobID']);
$salary = $conn->real_escape_string($_POST['salary']);
$hireDate = $conn->real_escape_string($_POST['hireDate']);
$managerID = $conn->real_escape_string($_POST['managerID']);
$departmentID = $conn->real_escape_string($_POST['departmentID']);
$username = $conn->real_escape_string($_POST['username']);
$creationID = $conn->real_escape_string($_POST['creationID']);
if (isset($_FILES['image']) && $_FILES['image']['error']==0){
$image = file_get_contents($_FILES['image']['tmp_name']);
} else {
// Handle no file uploaded or an error occurred
$image = null; // Adjust as needed
}
// Add other fields here...
// Use prepared statements to prevent SQL injection
$updateQuery = "UPDATE employees SET firstName=?, lastName=?, address=?, city=?, state=?, zipCode=?, phoneNumber=?, email=?, jobID=?, salary=?, hireDate=?, managerID=?, departmentID=?, username=?, creationID=?, image=? WHERE empID=?";
$stmt = $conn->prepare($updateQuery);
$stmt->bind_param("ssssssssdssdissi", $firstName, $lastName, $address, $city, $state, $zipCode, $phoneNumber, $email, $jobID, $salary, $hireDate, $managerID, $departmentID, $username, $creationID, $image, $empID);
if ($stmt->execute()){
echo "Employees table updated successfully";
} else {
echo "Error updating employees table: ". $conn->error;
}
$stmt->close();
$conn->close();
}
}
// Retrieve employees table information from the database
$conn = connectToDatabase(); // Connect to the database
$query = "SELECT * FROM employees";
$result = $conn->query($query);
?>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain the benefits of visualization.

Answered: 1 week ago