0% found this document useful (0 votes)
351 views

XXXXXXXXXX

Here is the complete code to update staff status when the checkbox is clicked: <?php include('includes/config.php'); if(isset($_POST['id']) && isset($_POST['status'])) { $id = $_POST['id']; $status = $_POST['status']; $sql = "UPDATE staff_tb SET status = :status WHERE id = :id"; $query = $dbh->prepare($sql); $query->bindParam(':status', $status, PDO::PARAM_INT); $query->bindParam(':id', $id, PDO::PARAM_INT); $query->execute(); echo "Status updated

Uploaded by

Asna Mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
351 views

XXXXXXXXXX

Here is the complete code to update staff status when the checkbox is clicked: <?php include('includes/config.php'); if(isset($_POST['id']) && isset($_POST['status'])) { $id = $_POST['id']; $status = $_POST['status']; $sql = "UPDATE staff_tb SET status = :status WHERE id = :id"; $query = $dbh->prepare($sql); $query->bindParam(':status', $status, PDO::PARAM_INT); $query->bindParam(':id', $id, PDO::PARAM_INT); $query->execute(); echo "Status updated

Uploaded by

Asna Mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

I apologize for the mistake.

Here's the updated code with the missing parts:

php

Copy code

<!-- Company List -->

<div class="row">

<div class="col-md-12">

<div class="table-responsive">

<table class="table table-hover custom-table datatable mb-0">

<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

$sql = "SELECT staff_tb.*, designation_tb.name as designation_name,


office_branch_tb.name as branch_name

FROM staff_tb

JOIN designation_tb ON staff_tb.designation_id = designation_tb.id

JOIN office_branch_tb ON staff_tb.office_branch_id = office_branch_tb.id";

$query = $dbh->prepare($sql);
$query->execute();

$results = $query->fetchAll(PDO::FETCH_OBJ);

$cnt = 1;

if ($query->rowCount() > 0) {

foreach ($results as $row) {

?>

<tr>

<td><?php echo htmlentities($cnt); ?></td>

<td>

<h2 class="table-avatar">

<a href="client-profile.html" class="avatar"><img src="profileimages/<?php


echo $row->photo; ?>" alt=""></a>

<a href="profile.php"><?php echo htmlentities($row->first_name); ?>&nbsp;<?


php echo htmlentities($row->last_name); ?></a>

</h2>

</td>

<td><?php echo htmlentities($row->mobile); ?></td>

<td><?php echo htmlentities($row->email); ?></td>

<td><?php echo htmlentities($row->pf_no); ?></td>

<td><?php echo htmlentities(date("d-m-Y", strtotime($row->Regdate))); ?></td>

<td><?php echo htmlentities($row->branch_name); ?></td>

<td><?php echo htmlentities($row->designation_name); ?></td>

<td>

<a class="btn btn-primary btn-sm" href="edit_staff.php?id=<?php echo $row-


>id; ?>">Edit</a>

</td>

<td>

<div class="status-toggle">

<input type="checkbox" id="status_<?php echo $row->id; ?>" class="check" <?


php if($row->status == 1) { echo 'checked'; } ?>>

<label for="status_<?php echo $row->id; ?>" class="checktoggle" data-id="<?


php echo $row->id; ?>"></label>

</div>
</td>

</tr>

<?php

$cnt = $cnt + 1;

?>

</tbody>

</table>

</div>

</div>

</div>

<!-- /Company List -->

<!-- jQuery -->

<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:
[email protected]

<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:

finish this code please

Sure! Here's the complete code with the AJAX request:

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) {

// do something on success, like show a success message

console.log(response);

},

error: function(xhr, status, error) {

// handle errors here

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.

[email protected]

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

$sql = "SELECT staff_tb.*, designation_tb.name as designation_name, office_branch_tb.name as


branch_name
FROM staff_tb

JOIN designation_tb ON staff_tb.designation_id = designation_tb.id

JOIN office_branch_tb ON staff_tb.office_branch_id = office_branch_tb.id";

$query = $dbh->prepare($sql);

$query->execute();

$results = $query->fetchAll(PDO::FETCH_OBJ);

$cnt = 1;

if ($query->rowCount() > 0) {

foreach ($results as $row) {

?>

<tr>

<td><?php echo htmlentities($cnt); ?></td>

<td>

<h2 class="table-avatar">

<a href="client-profile.html" class="avatar"><img src="profileimages/<?php echo $row-


>photo; ?>" alt="">

<a href="profile.php"><?php echo htmlentities($row->first_name); ?>&nbsp;<?php echo


htmlentities($row->last_name); ?></a>

</h2>

</td>

<td><?php echo htmlentities($row->mobile); ?></td>

<td><?php echo htmlentities($row->email); ?></td>

<td><?php echo htmlentities($row->pf_no); ?></td>

<td><?php echo htmlentities(date("d-m-Y", strtotime($row->Regdate))); ?></td>

<td><?php echo htmlentities($row->branch_name); ?></td>

<td><?php echo htmlentities($row->designation_name); ?></td>

<td>

<a class="btn btn-primary btn-sm" href="#" data-toggle="modal" data-target="#edit_staff_<?


php echo $row->id; ?>">Edit</a>

<!-- Edit Modal -->

<div class="modal fade" id="edit_staff_<?php echo $row->id; ?>" tabindex="-1" role="dialog"


aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">

<div class="modal-content">

<div class="modal-header">

<h5 class="modal-title" id="exampleModalLabel">Edit Staff Member</h5>

<button type="button" class="close" data-dismiss="modal" aria-label="Close">

<span aria-hidden="true">&times;</span>

</button>

</div>

<div class="modal-body">

<!-- Edit Form -->

<form action="update_staff.php" method="POST">

<input type="hidden" name="id" value="<?php echo $row->id; ?>">

<div class="form-group">

<label for="first_name">First Name</label>

<input type="text" class="form-control" id="first_name" name="first_name"


value="<?php echo $row->first_name; ?>" required>

</div>

<div class="form-group">

<label for="last_name">Last Name</label>

<input type="text" class="form-control" id="last_name" name="last_name"


value="<?php echo $row->last_name; ?>" required>

</div>

<div class="form-group">

<label for="mobile">Mobile</label>

<input type="text" class="form-control" id="mobile" name="mobile" value="<?php


echo $row->mobile; ?>" required>

</div

[email protected]

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');

if(isset($_POST['id']) && isset($_POST['status'])) {

$id = $_POST['id'];

$status = $_POST['status'];

$sql = "UPDATE staff_tb SET status = :status WHERE id = :id";

$query = $dbh->prepare($sql);

$query->bindParam(':status', $status, PDO::PARAM_INT);

$query->bindParam(':id', $id, PDO::PARAM_INT);

$query->execute();

echo "Status updated successfully";

} else {

echo "Error: Missing parameters";

?>

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',

data: {id: id, status: status},

success: function(response) {

console.log(response);

},

error: function(xhr, status, error) {

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.

[email protected]

write all code in one file

Here is the updated code with all functionalities in one file:

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'];

$sql="update staff_tb set


first_name=:fname,email=:email,mobile=:mobile,pf_no=:pfno,designation_id=:designation,office_br
anch_id=:officebranch,status=:status where id=:staffid";

$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();

$_SESSION['msg']="Staff Details updated successfully";

header('location:manage-staff.php');
}

?>

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Manage Staff</title>

<!-- Bootstrap CSS -->

<link rel="stylesheet" href="assets/css/bootstrap.min.css">

<!-- Fontawesome CSS -->

<link rel="stylesheet" href="assets/css/font-awesome.min.css">

<!-- Lineawesome CSS -->

<link rel="stylesheet" href="assets/css/line-awesome.min.css">

<!-- Datatable CSS -->

<link rel="stylesheet" href="assets/css/dataTables.bootstrap4.min.css">

<!-- Select2 CSS -->

<link rel="stylesheet" href="assets/css/select2.min.css">

<!-- Main CSS -->

<link rel="stylesheet" href="assets/css/style.css">

</head>

<body>

<!-- Main Wrapper -->

<div class="main-wrapper">

<!-- Header -->


<?php include('header.php'); ?>

<!-- /Header -->

<!-- Sidebar -->

<?php include('sidebar.php'); ?>

<!-- /Sidebar -->

<!-- Page Wrapper -->

<div class="page-wrapper">

<div class="content container-fluid">

<!-- Page Header -->

<div class="page-header">

<div class="row align-items

Regenerate response

ChatGPT Feb 13 Version. Free Research Preview. Our

You might also like