Link to home
Start Free TrialLog in
Avatar of Alex Lord
Alex Lord

asked on

Adding Array Values into database

How do i enter array value into database.


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";

Open in new window


Result -

User generated image
The Array -

User generated image
the field chk_name needs to equal that of the array
ASKER CERTIFIED SOLUTION
Avatar of Russell Fox
Russell Fox
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alex Lord
Alex Lord

ASKER

how does this work for pdo or is it same way ?
$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();
}