Multiple INSERT's by PHP using checkboxes

PellCearory

New Member
I have this piece of code I've done so far:\[code\]$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"); }}\[/code\]Which would use this list of checkboxes:\[code\]<input type="checkbox" value="http://stackoverflow.com/questions/3685930/<?php echo $row['user_id']; ?>" id="<?php echo $row['username']; ?>" class="usercheckbox" name="assign[]" />\[/code\]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:\[quote\] Notice: Undefined index: assign in [..] on line 41 not an array NULL\[/quote\]So basically the checkboxes have nothing, the checkboxes already have values in them, the \[code\]assign[]\[/code\] is correct, now I don't know what the problem is that it doesn't contain anything when submitting the form.
 
Back
Top