Input data ke 2 tabel dengan php

By On Saturday, October 1st, 2022 Categories : Tanya Jawab

Input data ke 2 tabel dengan php – Pa kabar sobs semua, Terima Kasih sudah berkunjung ke website trendwisata.com ini. Siang ini, kita dari portal TrendWisata dotcom ingin sharing tanya jawab yang bagus tentang Input data ke 2 tabel dengan php. Sebaiknya sobat menyimak dibawah ini:

  • saya masih pemula bang, belum banyak mengerti. mohon bantuan nya bang

  • modelguru.php

  • <?php

  • class Modelguru extends CI_Model

  • function __construct()

  • parent :: __construct();

  • function simpanguru($nip,$namaguru,$pendter,$jabatan,$tamatan,$komke,$thnsertifikasi,$status,$alamat,$nohp,$data)

  • if($data==‘baru’)

  • $hasil=$this->db->simple_query(“insert into guru(nip,namaguru,pendter,jabatan,tamatan,komke,thnsertifikasi,status,alamat,nohp) values(‘$nip‘,’$namaguru‘,’$pendter‘,’$jabatan‘,’$tamatan‘,’$komke‘,’$thnsertifikasi‘,’$status‘,’$alamat‘,’$nohp‘)”);

  • else

  • $hasil=$this->db->simple_query(“update guru set namaguru=’$namaguru‘,pendter=”$pendter“,jabatan=’$jabatan‘,tamatan=’$tamatan‘,komke=”$komke“,thnsertifikasi=’$thnsertifikasi‘,status=”$status“,alamat=”$alamat“,nohp=’$nohp‘ where nip=’$nip‘”);

  • return$hasil;

  • function cariguru($cari)

  • $hasil=$this->db->query(“select * from guru where nip = ‘$cari‘ or namaguru like ‘%$cari%'”);

  • return $hasil;

  • function gurukosong()

  • $hasil=$this->db->query(“select ” as nip, ” as namaguru,”as pendter,”as jabatan,”as tamatan,”as komke,”as thnsertifikasi,”as status,” as alamat,”as nohp”);

  • return $hasil;

  • function hapusguru($nip)

  • $hasil=$this->db->query(“delete from guru where nip=’$nip‘”);

  • return $hasil;

  • function editguru($where,$table)

  • return $this->db->get_where($table,$where);

  • ?>

  • viewguru.php

  • <body onload=”document.frmguru.guru.focus()”>

  • <?php

  • $b=$guru->row_array();

  • ?>

  • <!– page content –>

  • <div class=””>

  • <div class=”page-title”>

  • <div class=”title_left”>

  • <h3>Manajemen Guru</h3>

  • </div>

  • <div class=”title_right”>

  • <div class=”col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search”>

  • <div class=”input-group”>

  • </div>

  • </div>

  • </div>

  • </div>

  • <div class=”clearfix”></div>

  • <div class=”row”>

  • <div class=”col-md-12 col-sm-12 col-xs-12″>

  • <div class=”x_panel”>

  • <div class=”x_title”>

  • <h2>Form Input Data Guru</h2>

  • <ul class=”nav navbar-right panel_toolbox”>

  • <li><a class=”collapse-link”><i class=”fa fa-chevron-up”></i></a>

  • </li>

  • <li><a class=”close-link”><i class=”fa fa-close”></i></a>

  • </li>

  • </ul>

  • <div class=”clearfix”></div>

  • </div>

  • <div class=”x_content”>

  • <br />

  • <form id=”demo-form2″ data-parsley-validate class=”form-horizontal form-label-left” name=”frmguru” method=”post” action=”simpanguru”>

  • <input type=”hidden” name=”data” value=”<?php echo $data?>“/>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”nip” value=”<?php echo $kode?>” >NIP<span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <input type=”text” id=”nip” name=”nip” required=”required” class=”form-control col-md-7 col-xs-12″>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”namaguru” value=”<?php echo $b[‘namaguru’]?>“>Nama Guru <span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <input type=”text” id=”namaguru” name=”namaguru” required=”required” class=”form-control col-md-7 col-xs-12″>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label for=”pendter” class=”control-label col-md-3 col-sm-3 col-xs-12″>Pendidikan Terakhir<span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <select id=”jenis” required=”required” class=”form-control col-md-7 col-xs-12″ type=”text” name=”pendter” id=”pendter()” value=”<?php echo $b[‘pendter’]?>“>

  • <option value=””>Pilih Pendidikan Terakhir ….</option>

  • <option value=”Sekolah Menengah Akhir”>Sekolah Menengah Akhir</option>

  • <option value=”Diploma 3″>Diploma 3</option>

  • <option value=”Diploma 4″>Diploma 4</option>

  • <option value=”Strata 1″>Strata 1</option>

  • </select>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”jabatan” value=”<?php echo $b[‘jabatan’]?>“>Jabatan Terakhir <span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <input type=”text” id=”jabatan” name=”jabatan” required=”required” class=”form-control col-md-7 col-xs-12″>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”tamatan” value=”<?php echo $b[‘tamatan’]?>“>Tamatan <span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <input type=”text” id=”tamatan” name=”tamatan” required=”required” class=”form-control col-md-7 col-xs-12″>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”komke” value=”<?php echo $b[‘komke’]?>“>Kompetensi Keahlian <span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <input type=”text” id=”komke” name=”komke” required=”required” class=”form-control col-md-7 col-xs-12″>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”thnsertifikasi” value=”<?php echo $b[‘thnsertifikasi’]?>“>Tahun Sertifikasi <span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <select type=”text” id=”thnsertifikasi” name=”thnsertifikasi” required=”required” class=”form-control col-md-7 col-xs-12″>

  • <?PHP

  • $tahun = 1970; #tahun awal 1970

  • while ($tahun!=date(‘Y’) + 1)

  • echo “<option>$tahun</option>”;

  • $tahun++;

  • ?>

  • </select>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”status” value=”<?php echo $b[‘status’]?>“>Status Kepegawaian <span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <input type=”text” id=”status” name=”status” required=”required” class=”form-control col-md-7 col-xs-12″>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”alamat” value=”<?php echo $b[‘alamat’]?>“>Alamat <span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <input type=”text” id=”alamat” name=”alamat” required=”required” class=”form-control col-md-7 col-xs-12″>

  • </div>

  • </div>

  • <div class=”form-group”>

  • <label class=”control-label col-md-3 col-sm-3 col-xs-12″ for=”nohp” value=”<?php echo $b[‘nohp’]?>“>No HP<span class=”required”>*</span>

  • </label>

  • <div class=”col-md-6 col-sm-6 col-xs-12″>

  • <input type=”text” id=”nohp” name=”nohp” required=”required” class=”form-control col-md-7 col-xs-12″>

  • </div>

  • </div>

  • <div class=”ln_solid”></div>

  • <div class=”form-group”>

  • <div class=”col-md-9 col-sm-9 col-xs-12 col-md-offset-3″>

  • <button type=”submit” class=”btn btn-dark”><img src=”” class=”fa fa-save”> Simpan </button>

  • <button type=”button” class=”btn btn-dark” onclick=”location.href=(‘<?php echo base_url().‘index.php/guru/tambahguru’;?>‘)”/> <img src=”” class=”fa fa-arrow-circle-left”> Back </button>

  • </div></div></form></div></div></div></div></div></div></body>

  • controllerguru.php

  • <?php

  • class guru extends CI_controller

  • function __Construct()

  • parent :: __construct();

  • $this->load->model(‘modelguru’);

  • $this->load->helper(array(‘form’,‘url’));

  • function tambahguru()

  • if(!empty($_POST[‘txtcari’]))

  • $cari=$_POST[‘txtcari’];

  • else

  • $cari=;

  • $v[‘guru’]=$this->modelguru->cariguru($cari);

  • $x[‘judul’]=“CARI guru”;

  • $v[‘cari’]=$cari;

  • $x[‘isi’]=$this->load->view(‘vguru’,$v,true);

  • $this->load->view(‘tampilan’,$x);

  • function formguru()

  • if(!empty($_POST[‘nip’]))

  • $data=‘lama’;

  • $kode=$_POST[‘nip’];

  • $guru=$this->modelguru->cariguru($kode);

  • else

  • $data=‘baru’;

  • $kode=“”;

  • $guru=$this->modelguru->gurukosong();

  • $v[‘data’]=$data;

  • $v[‘kode’]=$kode;

  • $v[‘guru’]=$guru;

  • $x[‘judul’]=‘INPUT/EDIT guru’;

  • $x[‘isi’]=$this->load->view(‘vformguru’,$v,true);

  • $this->load->view(‘tampilan’,$x);

  • function simpanguru()

  • $data=$_POST[‘data’];

  • $nip=$_POST[‘nip’];

  • $namaguru=$_POST[‘namaguru’];

  • $pendter=$_POST[‘pendter’];

  • $jabatan=$_POST[‘jabatan’];

  • $tamatan=$_POST[‘tamatan’];

  • $komke=$_POST[‘komke’];

  • $thnsertifikasi=$_POST[‘thnsertifikasi’];

  • $status=$_POST[‘status’];

  • $alamat=$_POST[‘alamat’];

  • $nohp=$_POST[‘nohp’];

  • $simpan=$this->modelguru->simpanguru($nip,$namaguru,$pendter,$jabatan,$tamatan,$komke,$thnsertifikasi,$status,$alamat,$nohp,$data);

  • if($simpan==true)

  • $x[‘isi’]=“DATA SUKSES DISIMPAN <br> <a href=””.base_url().“index.php/guru/tambahguru”>Kembali</a>”;

  • else

  • $x[‘isi’]=“DATA GAGAL DISIMPAN <br> <a href=”https://kafesentul.com/javascript:history.back()”>Kembali</a>”;

  • $x[‘judul’]=“HASIL SIMPAN”;

  • $this->load->view(‘tampilan’,$x);

  • function hapusguru()

  • $nip=$_POST[‘nip’];

  • $this->modelguru->hapusguru($nip);

  • redirect(‘guru/tambahguru’);

  • function editguru($id)

  • $where = array(‘id’ => $id);

  • $data[‘username’] = $this->modelguru->editguru($where,‘username’)->result();

  • $this->load->view(‘guru/tambahguru’,$data);

  • ?>

  • Input data ke 2 tabel dengan php | admin | 4.5
    shopee flash sale gratis ongkir
    x