Bangun array dengan kunci dan nilai
$myarray = array("id"=>'',"title"=>$title,"body"=>$body,"pid"=>$rowId);
dan Gunakan PDO bukannya mysql_* fungsi (disusutkan).
$sql=$dbh->prepare("INSERT INTO `posts`(`id`, `title`, `body`, `post_id`) VALUES (:id,:title,:body,:pid)");
foreach($myarray as $row=>$value){
$sql->bindValue(":".$row,$value);
}
$sql->execute();
Selengkapnya Tentang PDO :http://www.php.net/manual/en/book. pdo.php