Alex Lord
asked on
Adding Array Values into database
How do i enter array value into database.
My Sql
Result -
The Array -
the field chk_name needs to equal that of the array
My Sql
$stmt = new Database();
//Inserting check state.
$query = "INSERT INTO a_test (charityID, contactID, chk_name) VALUES (:clientId, :contactId, :chkName) ";
$stmt->query( $query );
$stmt->bind( ':clientId', $clientId );
$stmt->bind( ':contactId', $contactId );
$stmt->bind( ':chkName', $_POST['chkStateCollection'] );
$stmt->execute();
$result = "Record added";
Result -
The Array -
the field chk_name needs to equal that of the array
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$stmt = $pdo->prepare('INSERT INTO a_test VALUES(:a, :b, :c)');
foreach($data as $item)
{
$stmt->bindValue(':a', $item[0]);
$stmt->bindValue(':b', $item[1]);
$stmt->bindValue(':c', $item[2]);
$stmt->execute();
}
foreach($data as $item)
{
$stmt->bindValue(':a', $item[0]);
$stmt->bindValue(':b', $item[1]);
$stmt->bindValue(':c', $item[2]);
$stmt->execute();
}
ASKER