I'm trying to get the ID from an URL like this: (the 37 is the ID)
http://localhost/myQSP/public/assign-qsps.php?employeeName=37
And insert it into a database along with a checkbox selection.
Database
id | employees_fk | qsps_fk | checked
1 37 101 1
2 37 102 1
The qsps_fk is a relational table. Using this Process code
<?php
if (isset($_POST['submit'])) {
$assign_qsps_id = $_POST["hidden-qsp-checkBoxes"];
$hidden_qsp = $_POST["department-qsp-checkBoxes"];
if(isset($_POST['hidden-qsp-checkBoxes'])) {
foreach ($assign_qsps_id as $qsp_id){
$visible_assign_qsp = in_array($qsp_id, $hidden_qsp) ? 1 : 0;
$query = "INSERT INTO junction_employees_qsps (qsps_fk, checked) VALUES ($qsp_id, $visible_assign_qsp);
$result = mysqli_query($db_connection, $query);
}
}
}
?>
It will create a table like this
id | employees_fk | qsps_fk | checked
1 0 101 1
2 0 102 1
My form is
<form action="assign-qsps-process.php" method="post">
<input type="submit" name="submit" value="ASSIGN QSP'S" />
<ul>
<?php $employee_qsps = find_departments_for_assign_qsps($current_employee['id']);
while($qsp = mysqli_fetch_assoc($employee_qsps)) { ?>
<li>
<input type='checkbox' name='hidden-qsp-checkBoxes[]' value='<?php htmlentities($qsp["qsp_id"]); ?>' style='display:none' checked='checked' />";
<input type='checkbox' name='department-qsp-checkBoxes[]' value='<?php htmlentities($qsp["qsp_id"]); ?>' />
<?php echo htmlentities($qsp['qsp_name']); ?>
</li>
}
</ul>
</form>
So how do I get the ID from the URL inserted with the checkbox selection along with makeing the employees_fk a relational table?
I've tried this and it doesn't work.
<?php
if (isset($_POST['submit'])) {
$id_employee = $current_employee["id"];
$assign_qsps_id = $_POST["hidden-qsp-checkBoxes"];
$hidden_qsp = $_POST["department-qsp-checkBoxes"];
if(isset($_POST['hidden-qsp-checkBoxes'])) {
foreach ($assign_qsps_id as $qsp_id){
$visible_assign_qsp = in_array($qsp_id, $hidden_qsp) ? 1 : 0;
$query = "INSERT INTO junction_employees_qsps (employees_fk, qsps_fk, checked) VALUES ($id_employee, $qsp_id, $visible_assign_qsp);
$result = mysqli_query($db_connection, $query);
}
}
}
?>
Thank you! I really appreciate the Help!
Aucun commentaire:
Enregistrer un commentaire