1

A form on another page posts to this updater.php page. I am trying to take some info from a group of checkboxes and insert them into a db.

updater.php

$privileges = $_POST['privileges'];
$N = count($privileges);
$conn = $GLOBALS['conn'];
$empID = $_POST['empID'];

for($i=0; $i<$N; $i++)
{
    $deptID = $privileges[$i];
    $query = "INSERT INTO employee_department (employeeID, departmentID)
           VALUES (':empID', ':deptID')";

    $smt = $conn->prepare($query);
    $smt->bindParam(':empID', $empID);
    $smt->bindParam(':deptID', $deptID);
    $smt->execute();
}

This code will work if I replace the placeholders with constants or if I replace them with$empID and $deptID. So I think the only thing that isn't working is where I'm trying to bind parameters to the placeholders. Thanks for any help!

Brent Connor
  • 636
  • 2
  • 6
  • 22
  • 3
    The placeholders `:empID, :deptID` must be _unquoted_ in the prepared statement. PDO will handle the quoting. – Michael Berkowski Sep 16 '14 at 13:24
  • 1
    Thanks, Michael. It's those little mistakes that keep me looking forever! I don't know how many adjustments I must have made in the past two hours. – Brent Connor Sep 16 '14 at 13:39

0 Answers0