<?php
$servername = "localhost"; // Change this to your server
name
$username = "root"; // Change this to your database
username
$password = ""; // Change this to your database password
$dbname = "dbEMP";
// Create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection
failed: " . $conn->connect_error);
}
// Process form submission
if (isset($_POST['update'])) {
$empno = $_POST['empno'];
$newDept =
$_POST['new_dept'];
// Update department for
the given Empno
$sql = "UPDATE
Employee SET Dept = '$newDept' WHERE Empno = '$empno'";
if ($conn->query($sql)
=== TRUE) {
echo "Department
updated successfully<br>";
} else {
echo "Error
updating department: " . $conn->error . "<br>";
}
}
// Close the connection
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Update
Employee Department</title>
</head>
<body>
<h1>Update Employee
Department</h1>
<form
method="post" action="">
<label
for="empno">Employee Number (Empno):</label>
<input
type="text" name="empno" required><br>
<label for="new_dept">New
Department:</label>
<input
type="text" name="new_dept" required><br>
<input
type="submit" name="update" value="Update
Department">
</form>
</body>
</html>
No comments:
Post a Comment