I am working on a project of HRMS ‘Human Resource Management System’
And task management is one of the module that includes in my project but I am stuck when I am getting the multi-select form user input I didn’t get the employees id in $_POST['assign-to[]']
you can see I the assign-to select value is an array, so basically I want to ask that how do I loop this variable and send to database using PHP and the complete backend code of action script are given below kindly take a look my code and help me if any other thing you need ask me
<?php
require_once 'db.inc.php';
if (isset($_POST['task-submit'])) {
$task_title = $_POST['task-title'];
$assignTo = $_POST['assign-to[]'];
$startDate =strtotime($_POST['start-date']);
$dueDate = strtotime($_POST['due-date']);
$descript = $_POST['descrp'];
if (empty($task_title || $assign_to || $start_date || $due_date || $descript)){
header("Location: ../admin/add-new-task.php?error=emptyfields&start_date".$startDate."&end_date=".$dueDate."&assignto=".$assignTo."&task_title".$task_title, true);
exit();
}
else if (!preg_match("/^[a-zA-Z0-9]*$/", $task_title)) {
header("Location: ../admin/add-new-task.php?error=invalid-Title", true);
exit();
}
elseif (!empty($assignTo)) {
foreach ($assignTo as $empId) {
echo "</br>";
echo "$empId";
}
}
else {
$sql = "INSERT INTO sys_task(task,start_date,due_date,description) VALUES (?, ?, ?, ?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../admin/add-new-task.php?error=sqlError", true);
exit();
}
else {
mysqli_stmt_bind_param($stmt, 'siis',$task_title,$startDate,$dueDate,$descript);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
header("Location: ../admin/add-new-task.php?result=Task_is_successfully_added&start_date=".$startDate."&end_date=".$dueDate."&assignto=".$assignTo."&task_title".$task_title, true);
exit();
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
Thank you