<?php
include_once("../../functions/db_conn.php");
$emp_id = isset($_GET['emp_id']) ? $_GET['emp_id'] : null;
if ($emp_id !== null) {
$db_conn = connection();
$query = "SELECT * FROM emp_tbl WHERE emp_id = $emp_id";
$stmt = mysqli_prepare($db_conn, $query);
if (!$stmt) {
die("Error in SQL query: " . mysqli_error($db_conn));
}
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (!$result) {
die("Error in fetching data: " . mysqli_error($db_conn));
}
$row = mysqli_fetch_array($result);
} else {
echo "Employee ID not provided in the URL.";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!--
</head>
<body>
<div class="container">
<div class="card mt-3">
<div class="card-header">
<h3>Edit Employee Details</h3>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<form id="empEditForm"
action="editUser.php" method="post">
<!--
<input type="hidden"
name="empId" value="<?php echo
$row['emp_id']; ?>">
<div class="form-group">
<label for="empName">EMP Name</label>
<input type="text" name="empName"
id="empName" class="form-control"
value="<?php echo $row['emp_name']; ?>">
</div>
<div class="form-group mt-2">
<label for="empEmail">
EMP Email</label>
<input type="email"
name="empEmail" id="empEmail"
class="form-control"
value="<?php
echo $row['emp_email']; ?>">
</div>
<div class="form-group mt-2">
<label for="empNic">
EMP NIC</label>
<input type="text" name="empNic"
id="empNic" class="form-control"
value="<?php echo $row['emp_nic']; ?>">
</div>
<div class="form-group mt-2">
<label for="empTel">
EMP Phone</label>
<input type="text" name="empTel"
id="empTel" class="form-control"
value="<?php echo $row['emp_tel']; ?>">
</div>
<div class="form-group mt-2">
<label for="empDob">
EMP DOB</label>
<input type="date" name="empDob"
id="empDob" class="form-control"
value="<?php echo $row['emp_dob']; ?>">
</div>
<!--
<!--
<div class="form-group mt-2">
<input type="submit" name="btnSave" id="btnSave" class="btn btn-success" value="Save">
</div>
</form>
</div>
<div class="col-md-2"></div>
</div>
</div>
</div>
</div>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>
$('#btnSave').click(function(e){
e.preventDefault();
$.ajax({
url: "../../route/emp/editUser.php",
type: "post",
data: $('#empEditForm').serialize() +
"&emp_id=<?php echo $emp_id; ?>",
success: function(data){
console.log('Response:', data);
if(data == '1'){
alert('Employee details updated successfully');
location.reload();
}else{
alert('Error');
}
}
});
});
</script>
What I have tried:
Employee ID not provided in the URL.
Edit Employee Details
EMP Name
Warning: Undefined variable $row in
C:\xampp\htdocs\ITproject\lib\views\emp\edituser.php on line
50
Warning: Trying to access array offset on value of type
null
in
C:\xampp\htdocs\ITproject\lib\views\emp\edituser.php on line
50
EMP Email
Warning: Undefined variable $row in
C:\xampp\htdocs\ITproject\lib\views\emp\edituser.php on line
54
Warning: Trying to access array offset on value of type
null
in
C:\xampp\htdocs\ITproject\lib\views\emp\edituser.php on line
54
EMP NIC
Warning: Undefined variable $row in
C:\xampp\htdocs\ITproject\lib\views\emp\edituser.php on line
58
Warning: Trying to access array offset on value of type
null
in
C:\xampp\htdocs\ITproject\lib\views\emp\edituser.php on line
58
EMP Phone
Warning: Undefined variable $row in
C:\xampp\htdocs\ITproject\lib\views\emp\edituser.php on line
62
Warning: Trying to access array offset on value of type
null
in
C:\xampp\htdocs\ITproject\lib\views\emp\edituser.php on line
62
EMP DOB
mm/dd/yyyy