Professional Documents
Culture Documents
php
Copy code
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Mobile</th>
<th>Email</th>
<th>PF N0</th>
<th>Created</th>
<th>Branch</th>
<th>Role</th>
<th>Action</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
FROM staff_tb
$query = $dbh->prepare($sql);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_OBJ);
$cnt = 1;
if ($query->rowCount() > 0) {
?>
<tr>
<td>
<h2 class="table-avatar">
</h2>
</td>
<td>
</td>
<td>
<div class="status-toggle">
</div>
</td>
</tr>
<?php
$cnt = $cnt + 1;
?>
</tbody>
</table>
</div>
</div>
</div>
<script src="js/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function() {
$('.checktoggle').on('click', function() {
var id = $(this).data('id');
var status = 0;
if ($('#status_' + id).is(':checked')) {
status = 1;
$.ajax({
url: 'update_status.php',
type: 'POST',
data:
neematomonja@gmail.com
<script>
$(document).ready(function() {
$('.checktoggle').on('click', function() {
var id = $(this).data('id');
var status = 0;
if ($('#status_' + id).is(':checked')) {
status = 1;
$.ajax({
url: 'update_status.php',
type: 'POST',
data:
php
Copy code
<script>
$(document).ready(function() {
$('.checktoggle').on('click', function() {
var id = $(this).data('id');
var status = 0;
if ($('#status_' + id).is(':checked')) {
status = 1;
$.ajax({
url: 'update_status.php',
type: 'POST',
data: {
id: id,
status: status
},
success: function(response) {
console.log(response);
},
console.log(xhr.responseText);
});
});
});
</script>
Make sure to replace update_status.php with the actual filename of the PHP script that updates the
status in the database. Also, make sure to add the code for updating the status in the PHP script.
neematomonja@gmail.com
i need to edit this code to be as update_status.php when user click the edit button will pop up this
code using id and will update the details
To update the details of a staff member when the user clicks on the "Edit" button, you need to
modify the code in the foreach loop of the table to include a modal that allows the user to edit the
details. Here's an example of what the modified code could look like:
php
Copy code
<?php
$query = $dbh->prepare($sql);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_OBJ);
$cnt = 1;
if ($query->rowCount() > 0) {
?>
<tr>
<td>
<h2 class="table-avatar">
</h2>
</td>
<td>
<div class="modal-content">
<div class="modal-header">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
</div>
<div class="form-group">
</div>
<div class="form-group">
<label for="mobile">Mobile</label>
</div
neematomonja@gmail.com
is that done?
No, the code you provided is still incomplete. You only have the SQL query, but not the PHP code to
execute it. Here's a complete example that should work for updating the staff status:
php
Copy code
<?php
include('includes/config.php');
$id = $_POST['id'];
$status = $_POST['status'];
$query = $dbh->prepare($sql);
$query->execute();
} else {
?>
To use this code, you need to send an AJAX POST request to it from your main page when the staff
status checkbox is clicked. The code should be something like this:
javascript
Copy code
$(document).ready(function() {
$('.checktoggle').on('click', function() {
var id = $(this).data('id');
var status = 0;
if ($('#staff_' + id).is(':checked')) {
status = 1;
}
$.ajax({
url: 'update_status.php',
type: 'POST',
success: function(response) {
console.log(response);
},
console.log(xhr.responseText);
});
});
});
Note that you need to replace update_status.php with the actual path to your PHP script, and you
should also modify the success and error functions to handle the server response in your own way.
neematomonja@gmail.com
php
Copy code
<?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
header('location:index.php');
else
if(isset($_POST['update']))
$staffid=intval($_GET['staffid']);
$fname=$_POST['fullname'];
$email=$_POST['email'];
$mobile=$_POST['mobileno'];
$pfno=$_POST['pfno'];
$designation=$_POST['designation'];
$officebranch=$_POST['officebranch'];
$status=$_POST['status'];
$query = $dbh->prepare($sql);
$query->bindParam(':fname',$fname,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':mobile',$mobile,PDO::PARAM_STR);
$query->bindParam(':pfno',$pfno,PDO::PARAM_STR);
$query->bindParam(':designation',$designation,PDO::PARAM_STR);
$query->bindParam(':officebranch',$officebranch,PDO::PARAM_STR);
$query->bindParam(':status',$status,PDO::PARAM_STR);
$query->bindParam(':staffid',$staffid,PDO::PARAM_STR);
$query->execute();
header('location:manage-staff.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Manage Staff</title>
</head>
<body>
<div class="main-wrapper">
<div class="page-wrapper">
<div class="page-header">
Regenerate response