hi im trying to insert data in mysql using array, can someone please look at my code, i cant seem to make it work.
this is my post.php
/* POST.PHP */
$post_id = somefunction();
$title = $_POST['title'];
$body = $_POST['body'];
$myarray = array('','$title','$body','$rowId');
insertToDB($myarray);
and this is inside my function.php
function insertToDB($myArray) {
$db = dbConnect();
$query = "INSERT INTO `posts`(`id`, `title`, `body`, `post_id`) VALUES ";
$valuesArr = $array();
foreach($myarray as $row) {
$id = (int)$row[0]; // as my primary, auto increment
$title = mysql_real_escape_string($row[1]);
$body = mysql_real_escape_string($row[2]);
$post_id = (int)$row[3];
$valuesArr[] = "(`id`, `title`, `body`, `post_id`)";
}
$sql .=implode(',', $valuesArr);
$db->query($sql);
}
please note that my $id = (int)$row[0];
is primary and auto increment.