Insert Di Code igniter
settingan Awal
config.php,database.php,autoload=>in folder aplication/config
config.php
$config['encryption_key'] = 'sanceainulyaqin';
$config['base_url'] = 'http://localhost:8080/form/'; //Sesuai dengan urlnya
database.php
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'form';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
autoload.php
$autoload['libraries'] = array('database','session');
$autoload['helper'] = array('url');
Buat database kemudian buat tablenya untk database localhost
jika sql server auto_incrementnya menjadi set_identity
create table tbsiswa(
id int primary key auto_increment,
nama_awal varchar(50),
nama_akhir varhar(50),
alamat text
)
config.php,database.php,autoload=>in folder aplication/config
config.php
$config['encryption_key'] = 'sanceainulyaqin';
$config['base_url'] = 'http://localhost:8080/form/'; //Sesuai dengan urlnya
database.php
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'form';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
autoload.php
$autoload['libraries'] = array('database','session');
$autoload['helper'] = array('url');
Buat database kemudian buat tablenya untk database localhost
jika sql server auto_incrementnya menjadi set_identity
create table tbsiswa(
id int primary key auto_increment,
nama_awal varchar(50),
nama_akhir varhar(50),
alamat text
)
For Design Form This Code
<?php echo $this->session->flashdata('srr')?>
<div id="frm">
<form action="<?php echo site_url('site/insert')?>" method="POST">
<fieldset>
<legend>Tambah Data</legend>
<label>Nama Awal</label>
<input type="text" name="nama_awal" placeholder="Enter Your First Name" required/>
<label>Nama Akhir</label>
<input type="text" name="nama_akhir" placeholder="Enter Your Last Name" />
<label>Alamat</label>
<textarea name="alamat" ></textarea>
<input type="submit" value="SAVE" name="add"/>
</form>
</fieldset>
</div>
Buat lah Controller Site dan buat function insert
public function insert()
{
$nama_awal=$this->input->post('nama_awal',true);
$nama_akhir=$this->input->post('nama_akhir',true);
$alamat=$this->input->post('alamat',true);
$object=array(
'nama_awal'=>$nama_awal, //nama field database
'nama_akhir'=>$nama_akhir, //nama field database
'alamat'=>$alamat //nama field database
);
$this->db->insert('tbsiswa',$object);
$this->load->view('welcome_message');
$this->session->set_flashdata('srr',"Data Berhasil di input");
}
Created by Sance ainul yaqin
Insert Di Code igniter
Reviewed by Leo
on
11:16
Rating:
No comments