0

i have json file, and the content is list country but when i save to my database, just the first sentence example if i save "united states", in the database just "united" i hope to save all, but i can't

var url_country="<?=base_url()?>country.json";
var negara_list ="<option value=''></option>";
    $.getJSON(url_country, function(data) {
      $.each(data,function(key,val){
         negara_list += "<option value="+val+">"+val+"</option>";
      });
      $(".negara").html(negara_list);
  });

this is the structur database

and this is function to save in database

$form=$this->input->post('form');
    $data=array(
        'NIS'                 =>$form['nis'],
        'NISN'                =>$form['nisn'],
        'NAMA_LENGKAP'        =>$form['nama_lengkap'],
        'KEWARGANEGARAAN'     =>$form['kewarganegaraan'],
        'BAHASA'              =>$form['bahasa']
    );
    if($this->model->cekNis($form['nis'])->num_rows()==0 && $form['nisn']!=''){
        $this->db->insert('m_siswa',$data);
        $d['status']=1;
        $d['keterangan']='data berhasil dimasukan';
    }else{
        $d['status']=0;
        $d['keterangan']="data sudah pernah di tambahkan sebelumnya";
    }
    $d['data']=$data;
    $this->json($d);
5
  • show us your DB structure it might be size issue or something else Commented Apr 6, 2019 at 3:30
  • can you show your save country function? Commented Apr 6, 2019 at 3:54
  • show me your $_POST data in var_dump($_POST); before the insert it to database Commented Apr 6, 2019 at 4:29
  • post sample json Commented Apr 6, 2019 at 4:38
  • what is $this->input->post('form')? Commented Apr 6, 2019 at 5:02

1 Answer 1

1

You might want to encapsulate the val input value with quotes so it's sending the whole string :

negara_list += "<option value='"+val+"'>"+val+"</option>";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.