简体   繁体   中英

Insert data failed using codeigniter and mysql

i have a little bit error when doing a simple registration form. My problem is the data that have input is not inserted in database.

But before i using horizontal form the data can be inserted in my database. I'm using MySQL. this is my controller :

function create(){  
$data = array(
            'nik' => $this->input->post('nik'),
            'nama' => $this->input->post('nama'),
            'tgl_lahir' =>$this->input->post('tgl_lahir'),
            'no_hp' => $this->input->post('no_hp'),
            'alamat' => $this->input->post('alamat')
        );
        $this->db->insert('profile_mitra',$data);
        redirect('admin/daftar_mitra');
    } 

and this my view called tambah_mitra.php.

View (tambah_mitra.php)

 <?php $this->load->view('templates/head');?> <?php $this->load->view('templates/sidebar');?> <body> <div class="content-wrapper"> <section class="content-header"> <section class="content"> <div class="row"> <!-- left column --> <div class="col-md-6"> <!-- general form elements --> <div class="box box-primary"> <div class="box-header with-border"> <h3 class="box-title">Tambah Mitra</h3> </div> <!-- /.box-header --> <!-- form start --> <form role="form"> <div class="box-body"> <div class="form-group"> <?php echo validation_errors();?> <?php echo form_open('admin/daftar_mitra');?> <label for="exampleInputEmail1">NIK</label> <input type="text" class="form-control" id="nik" placeholder="NIK"> </div> <div class="form-group"> <label for="exampleInputEmail1">Nama</label> <input type="text" class="form-control" id="nama" placeholder="Nama"> </div> <div class="form-group"> <label for="exampleInputEmail1">Tanggal Lahir</label> <input type="date" class="form-control" id="tgl_lahir" placeholder=""> </div> <div class="form-group"> <label for="exampleInputEmail1">No.HP</label> <input type="text" class="form-control" id="no_hp" placeholder="Nomor Handphone"> </div> <div class="form-group"> <label for="exampleInputPassword1">Alamat</label> <input type="alamat" class="form-control" id="alamat" placeholder="Alamat Lengkap"> </div> <!-- <div class="form-group"> <label for="exampleInputFile">File input</label> <input type="file" id="exampleInputFile"> <p class="help-block">Example block-level help text here.</p> </div> --> <!-- <div class="checkbox"> <label> <input type="checkbox"> Check me out </label> </div> --> </div> <!-- /.box-body --> <div class="box-footer"> <input class="btn btn-success" type="submit" value="Simpan"> </div> </form> </div> </div> </div> </section> </div> </body> <?php $this->load->view('templates/footer');?> 

it is not inserting because you did not define name of input filed.i think this is the reason of not inserting data. please try.

<div class="form-group">
                      <label for="exampleInputEmail1">Nama</label>
                      <input type="text" class="form-control" id="nama" name="nama" placeholder="Nama">
                    </div>

try closing your form

<?php echo form_close();?>

Also to see the errors use

<?php echo form_error('nik');  

and continue filling the (' ') in with your variables to see what the error is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM