I have the fallowing html:
<a href="./libs/php/edit.php?edit=<?php echo $row['lastName']; ?>" class="btn btn-info">Edit</a>
php script handling the data:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$executionStartTime = microtime(true);
include("config.php");
$conn = new mysqli($cd_host, $cd_user, $cd_password, $cd_dbname, $cd_port, $cd_socket) or
die(mysqli_error($conn));
$department = " ";
$location = " ";
$update = false;
if (mysqli_connect_errno()) {
$output['status']['code'] = "300";
$output['status']['name'] = "failure";
$output['status']['description'] = "database unavailable";
$output['status']['returnedIn'] = (microtime(true) - $executionStartTime) / 1000 . " ms";
$output['data'] = [];
mysqli_close($conn);
echo json_encode($output);
exit;
}
if (isset($_GET['editDepartment'])) {
$id = $_GET['editDepartment'];
$result = $conn->query("SELECT * FROM department WHERE id=$id") or die(mysqli_error($conn));
$update = true;
if (!$result) {
$output['status']['code'] = "400";
$output['status']['name'] = "executed";
$output['status']['description'] = "query failed";
$output['data'] = [];
mysqli_close($conn);
echo json_encode($output);
exit;
} else {
$row = $result->fetch_array();
$department = $row['name'];
$location = $conn->query("SELECT locationID FROM department WHERE id=$id") or
die(mysqli_error($conn));
}
};
and a modal which is already handling my 'create entry' feature :
<!-- Modal department-->
<div class="modal fade" id="department" 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">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="./libs/php/insertDepartment.php" method="POST">
<p><input type="text" name="departmentName" placeholder="Department name"
id="departmentName" value="<?php echo $name ?>"></p>
<select name="locationID" id="locationID">
<?php
foreach ($outputAllLoc['data'] as $item) {
echo "<option value='($item[id])'>$item[name]</option>";
}
?>
</select>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save changes</button>
</form>
</div>
</div>
</div>
</div>
<!-- end of modal -->
Is there a way to use that anchor tag to open this modal and send data to the PHP script? My goal is to have the same modal for creating entries and handling the edit feature. Thanks, everyone! Chi Chi