I have this piece of code I've done so far:
$assign = $_POST['assign'];
if(!empty($name) && !empty($description) && !empty($deadline))
{
if(validateDate($deadline))
{
$final_deadline = strtotime($deadline);
$sql .= "INSERT INTO projects
(project_id, project_name, project_description, project_deadline, project_status, project_priority)
VALUES ('" . $project_id . "', '" . $name . "', '" . $description . "', '" . $final_deadline . "', '" . $status . "', '" . $priority . "');";
if(is_array($assignments))
{
foreach($assignments as $assigned_user)
{
$sql .= "INSERT INTO assignments (user_id, project_id) VALUES('" . $assigned_user . "', '" . $project_id . "');";
}
}
else
{
echo '<br /><br />not an array<br />';
}
$result = mysql_query($sql) or die(mysql_error());
echo '<br />' . var_dump($assignments);
}
else
{
$_SESSION['ERROR'] = "Not a valid deadline";
header("Location: dashboard.php");
}
}
Which would use this list of checkboxes:
<input type="checkbox" value="<?php echo $row['user_id']; ?>" id="<?php echo $row['username']; ?>" class="usercheckbox" name="assign[]" />
The problem that comes is when I submit the form which is to insert a record for each of the checked boxes, it returns an empty array...
It says this:
Notice: Undefined index: assign in [..] on line 41
not an array
NULL
So basically the checkboxes have nothing, the checkboxes already have values in them, the assign[]
is correct, now I don't know what the problem is that it doesn't contain anything when submitting the form.