This is what I am trying to build query using implode why not excecute in database
if(isset($_POST['tambah'])){
$data1 = array(
'id' => $_POST['id'],
'nama' => $_POST['nama'],
'jk' => $_POST['jk'],
'tempat' => $_POST['tempat'],
'tanggal' => $_POST['tanggal'],
'formattgl' => date('d mmmm, yyyy',strtotime('$tanggal')),
'pekerjaan' => $_POST['pekerjaan'],
'alamat' => $_POST['alamat'],
'fotonama' => str_replace(' ', '-', $id.'.jpg'),
'filefoto' => move_uploaded_file($FILES['foto']['temp_name'], '..asset/img/anggota/'.$fotonama),
);
$db->tambahAnggota($data1);
}
Now I have to build query like this
function tambahAnggota($data1){
$kunci = implode(", ",array_keys($data1));
$i = 0;
foreach ($data1 as $key => $value) {
if (!is_int($value)){
$arrayValue[$i] = "'".$value."'";
}else{
$arrayValue[$i] = $value;
}
$i++;
}
$nilai = implode(", ", $arrayValue);
$s = "insert into anggota ($kunci)";
$s .= " VALUES ";
$s .= "($nilai)";
$sql = $this->db->query($s); /*or die (($this->db->connect_error($s)))*/
if($sql){
header("location: ?op=anggota");
}else {
echo "Connection failed ".$this->db->connect_errno;
}
}
How can I do it in above mentioned implode functions