contact
WA: 0822-8846-7823
SMS: 0822-8846-7823
Call: 0822-8846-7823
BBM: D7DB3491
ebsofmail@gmail.com

How to insert or update array to php mysql

Posted in PHP MYSQL / i Life at 26 Mei 2019 With 0 Comments


 

menyimpan data array ke dalam database

  $data = array();
        $ids = $_POST['id'];
        $input = $_POST['input'];  
        $edit = $_POST['edit'];
        $hapus = $_POST['hapus'];
        $cetak = $_POST['cetak'];
        if($ids ){
            foreach ($ids as $key => $value){
                $info_user = array(
                'user_id' => $value,
                'input' => !empty($input[$value]) ? 1: 0,
                'edit' => !empty($edit[$value]) ? 1: 0,
                'hapus' => !empty($hapus[$value]) ? 1: 0,
                'cetak' => !empty($cetak[$value]) ? 1: 0,
                );
                $data[] = $info_user;

            }   
        }
        
foreach ($data as $test) {
mysqli_query($konek, "UPDATE setting SET input = '$test[input]',edit = '$test[edit]', hapus = '$test[hapus]' , cetak = '$test[cetak]' WHERE id_set = '$test[user_id]'");

}

 


Artikel Rekomendasi

Artikel Terkait

Diskusi