I need to select a record in the modal form. The HTML code is,
<table class="table justify-content-center" style="background-color:white">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<thead style="background-color:green;color:white;font-weight:bold">
<tr>
<th>Employee Name</th>
<th>Employee ID</th>
<th>Designation</th>
<th>Phone</th>
<th>Actions</th>
</tr>
</thead>
<?php
while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['employeename']; ?></td>
<td><?php echo $row['employeeno']; ?></td>
<td><?php echo $row['designation']; ?></td>
<td><?php echo $row['contactnumber']; ?></td>
<td>
<button name="edit" class="editbtn"> <a href="#editEmployeeModal" data-toggle="modal" data-dismiss="modal" style="color: brown" >Edit</a> </button>
<button name="delete" class="btn btn-info " ><a href="employeelist.php?delete=<?php echo $row['id']; ?>" style="color: brown">Delete</a> </button>
</td>
</tr>
<?php endwhile; ?>
</table>
and the HTML for modal form is,
<!-- Edit Modal HTML -->
<div id="editEmployeeModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form action="employeeprocess.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="modal-header">
<h4 class="modal-title">Edit Employee</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Employee Number</label>
<input type="text" class="form-control" value="<?php $employeenum ?>" name="employeenum" required>
</div>
<div class="form-group">
<label>Employee Name</label>
<input type="text" class="form-control" name="employeename" value="<?php $employeename ?>" required>
</div>
<div class="form-group">
<label>Job Location</label>
<input type="text" class="form-control" name="joblocation" value="<?php $joblocation ?>" required>
</div>
<div class="form-group">
<label>DateofJoin</label>
<input type="date" class="form-control" name="dateofjoin" value="<?php $dateofjoin ?>" required>
</div>
<div class="form-group">
<label>Contact Number</label>
<input type="text" class="form-control" name="contactnumber" value="<?php $contactnumber ?>" required>
</div>
<div class="form-group">
<label>Designation</label>
<input type="text" class="form-control" name="designation" value="<?php $designation ?>" required>
</div>
<div class="form-group">
<label>Status</label>
<input type="text" class="form-control" name="status" value="<?php $status ?>" required>
</div>
<div class="form-group">
<label>Photo</label>
<input type="file" class="form-control" name="myfile" required>
</div>
</div>
<div class="modal-footer">
<input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
<input type="submit" class="btn btn-success" name="edit" value="Update">
</div>
</form>
</div>
</div>
</div>
employeeprocess.php
if (isset($_GET['delete'])){
$id = $_GET['delete'];
$mysqli->query("DELETE FROM employees WHERE id=$id") or die($mysqli->error());
$_SESSION['message'] = "Record has been deleted!";
$_SESSION['msg_type'] = "danger";
header("location: employeelist.php");
}
if (isset($_GET['edit'])){
$id = $_GET['edit'];
$update = true;
$result = $mysqli->query("SELECT * FROM employees WHERE id=$id") or die($mysqli->error());
if (count($result)==1){
$row = $result->fetch_array();
$employeenum = $row['employeenum'];
$employeename = $row['employeename'];
$joblocation = $row['joblocation'];
$dateofjoin = $row['dateofjoin'];
$contactnumber = $row['contactnumber'];
$designation = $row['designation'];
$status = $row['status'];
}
}
Javascript is
<script>
$(".editbtn").click(function () {
$('#edit').val($(this).data('id'));
});
</script>
I need to pass the selected record to the editEmployeeModal and set the variable edit for modal dialog to display the selected record. The modal is not working, if I put the statement href="#editEmployeeModal?edit= <?php echo $row['id']; ?>
" So, Can you suggest me to this problem?