Postingan lainnya
Kenapa ketika klik tombol update data justru kembali ke semula?
Saya sedang membuat update data,
ketika saya tes dengan mengubah data dan klik tombol update, justru tetap dihalaman yang sama dan data kembali seperti semula dan pesan error/berhasil tidak ada. mohon bantuan & pencerahannya.
<?php
require_once "connection.php";
if(isset($_REQUEST['update_id']))
{
try
{
$kdsiswa = $_REQUEST['update_id']; //get "update_id" from index.php page through anchor tag operation and store in "$id" variable
$select_stmt = $db->prepare('SELECT * FROM tb_siswa WHERE kd_siswa =:kdsiswa'); //sql select query
$select_stmt->bindParam(':kdsiswa',$kdsiswa);
$select_stmt->execute();
$row = $select_stmt->fetch(PDO::FETCH_ASSOC);
$namasiswa = $row['nama_siswa']; //textbox name "txt_firstname"
$tempatlahir = $row['tempat_lhr']; //textbox name "txt_lastname"
$tgllahir = $row['tgl_lhr'];
$jenkel = $row['jen_kel'];
$berat = $row['berat_bdn'];
$tinggi = $row['tinggi_bdn'];
$hslagama = $row['religion'];
$negara = $row['kebangsaan'];
$marital = $row['status_nikah'];
$address = $row['alamatsiswa'];
$hpsiswa = $row['hpsiswa'];
$telpsiswa = $row['telsiswa'];
$email = $row['emailsiswa'];
$study = $row['pendidikan'];
$sekolah = $row['nama_sklh'];
$alamatsekolah = $row['alamat_sklh'];
$family = $row['family'];
$familyname = $row['familyname'];
$alamatfamily = $row['alamat_ortu'];
$hportu = $row['hp_ortu'];
$tlportu = $row['tlp_ortu'];
$experience = $row['job_position'];
$perusahaan = $row['nm_perusahaan'];
$mulai = $row['tgl_start'];
$akhir = $row['tgl_end'];
$namaref = $row['nama_ref'];
$hasilprogram = $row['program'];
$hasilclass = $row['class'];
$hasiljob = $row['job'];
$image_file = $row['foto'];
}
catch(PDOException $e)
{
$e->getMessage();
}
}
?>
<?php
if(isset($_POST['btn_update']))
{
$namasiswaup = $_POST['txt_namasiswa']; //textbox name "txt_firstname"
$tempatlahirup = $_POST['txt_tempatlahir']; //textbox name "txt_lastname"
$tgllahirup = $_POST['tanggal'];
$jenkelup = $_POST['gender'];
$beratup = $_POST['txt_berat'];
$tinggiup = $_POST['txt_tinggi'];
$tinggiup = $_POST['txt_tinggi'];
$hslagamaup = $_POST['txt_agama'];
$negaraup = $_POST['txt_negara'];
$maritalup = $_POST['marital'];
$addressup = $_POST['txt_address'];
$hpsiswaup = $_POST['txt_hpsiswa'];
$telpsiswaup = $_POST['txt_telpsiswa'];
$emailup = $_POST['txt_email'];
$studyup = $_POST['study'];
$sekolah = $_POST['txt_sekolah'];
$alamatsekolahup = $_POST['txt_alamatsekolah'];
$familyup = $_POST['family'];
$familynameup = $_POST['txt_familyname'];
$alamatfamilyup = $_POST['txt_alamatortu'];
$hportuup = $_POST['txt_hportu'];
$tlportuup = $_POST['txt_tortu'];
$experienceup = $_POST['txt_experience'];
$perusahaanup = $_POST['txt_perusahaan'];
$mulaiup = $_POST['txt_start'];
$akhirup = $_POST['txt_akhir'];
$namarefup = $_POST['txt_namaref'];
$hasilprogramup = $_POST['txt_program'];
$hasilclassup = $_POST['txt_class'];
$hasiljobup = $_POST['txt_job'];
$image_fileup = $_FILES["images"]["name"];
$type = $_FILES["images"]["type"]; //file name "txt_file"
$size = $_FILES["images"]["size"];
$temp = $_FILES["images"]["tmp_name"];
$path="upload/".$image_fileup; //set upload folder path //textbox name "txt_lastname"
if(empty($namasiswaup)){
$errorMsg="Please Enter Class Code";
}
else if(empty($tempatlahirup)){
$errorMsg="Please Enter Place of Birth";
}
else if(empty($tgllahir)){
$errorMsg="Please Enter Date of Birth";
}
else if(empty($jenkelup)){
$errorMsg="Please Enter Gender";
}
else if(empty($beratup)){
$errorMsg="Please Enter Weight";
}
else if(empty($tinggiup)){
$errorMsg="Please Enter Height";
}
else if(empty($hslagamaup)){
$errorMsg="Please Enter Religion";
}
else if(empty($negaraup)){
$errorMsg="Please Enter Nationality";
}
else if(empty($maritalup)){
$errorMsg="Please Enter Marital";
}
else if(empty($hpsiswaup)){
$errorMsg="Please Enter Handphone Number";
}
else if(empty($emailup)){
$errorMsg="Please Enter Email";
}
else if(empty($image_fileup)){
$errorMsg="Please Select Image";
}
else if($type=="image/jpg" || $type=='image/jpeg' || $type=='image/png' || $type=='image/gif') //check file extension
{
if(!file_exists($path)) //check file not exist in your upload folder path
{
if($size < 5000000) //check file size 5MB
{
unlink($directory.$row['image']); //unlink function remove previous file
move_uploaded_file($temp, "upload/" .$image_file);
}
else
{
$errorMsg="Your File To large Please Upload 5MB Size"; //error message file size not large than 5MB
}
}
else
{
$errorMsg="File Already Exists...Check Upload Folder"; //error message file not exists your upload folder path
}
}
else
{
$errorMsg="Upload JPG , JPEG , PNG & GIF File Formate.....CHECK FILE EXTENSION"; //error message file extension
}
try
{
if(!isset($errorMsg))
{
//memulai update
$update_stmt=$db->prepare('UPDATE tb_siswa SET nama_siswa=:namasiswaup,
tempat_lhr=:tempatlahirup, tgl_lhr=:tgllahirup, jen_kel=:jenkelup, berat_bdn=:bbup, tinggi_bdn=:tbup, religion=:hslagamaup,
kebangsaan=:negaraup, status_nikah=:maritalup, alamatsiswa=:alamatup, hpsiswa=:hapesiswaup, telsiswa=:telpsiswaup,
emailsiswa=:emailup, pendidikan=:studyup, nama_sklh=:namasekolahup, alamat_sklh=:alamatsekolahup, family=familiesup,
familyname=:familynameup, alamat_ortu=:alamatortuup, hp_ortu=:hportuup, tlp_ortu=:telportuup, job_position=:experienceup,
nm_perusahaan=:perusahaanup, tgl_start=:mulaiup, tgl_end=:akhirup, nama_ref=:namarefup, program=:pprogram, job=:jjob,
class=cclass, foto=:images WHERE kd_siswa=:kdsiswa'); //sql insert query
$update_stmt->bindParam(':namasiswaup',$namasiswaup);
$update_stmt->bindParam(':tempatlahirup',$tempatlahirup); //bind all parameter
$update_stmt->bindParam(':tgllahirup',$tgllahirup);
$update_stmt->bindParam(':jenkelup',$jenkelup);
$update_stmt->bindParam(':bbup',$beratup);
$update_stmt->bindParam(':tbup',$tinggiup);
$update_stmt->bindParam(':hslagamaup',$hslagamaup);
$update_stmt->bindParam(':negaraup',$negaraup);
$update_stmt->bindParam(':maritalup',$maritalup);
$update_stmt->bindParam(':alamatup', $addressup);
$update_stmt->bindParam(':hapesiswaup', $hpsiswaup);
$update_stmt->bindParam(':telpsiswaup', $telpsiswaup);
$update_stmt->bindParam(':emailup', $emailup);
$update_stmt->bindParam(':studyup', $studyup);
$update_stmt->bindParam(':namasekolahup', $sekolahup);
$update_stmt->bindParam(':alamatsekolahup', $alamatsekolahup);
$update_stmt->bindParam(':familiesup', $familyup);
$update_stmt->bindParam(':familynameup', $familynameup);
$update_stmt->bindParam(':alamatortuup', $alamatfamilyup);
$update_stmt->bindParam(':hportuup', $hportuup);
$update_stmt->bindParam(':telportuup', $tlportuup);
$update_stmt->bindParam(':experienceup', $experienceup);
$update_stmt->bindParam(':perusahaanup', $perusahaanup);
$update_stmt->bindParam(':mulaiup', $mulaiup);
$update_stmt->bindParam(':akhirup', $akhirup);
$update_stmt->bindParam(':namarefup', $namarefup);
$update_stmt->bindParam(':pprogramup', $hasilprogramup);
$update_stmt->bindParam(':jjobup', $hasiljobup);
$update_stmt->bindParam(':cclassup', $hasilclassup);
$update_stmt->bindParam(':imagesup', $image_fileup);
$update_stmt->bindParam(':kdsiswa', $kdsiswa);
if($update_stmt->execute())
{
$insertMsg="Update Successfully"; //execute query success message
header("refresh:3;index_admin.php"); //refresh 3 second and redirect to index.php page
}
}
}
catch(PDOException $e)
{
echo "ada kesalahan : ".$e->getMessage();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
<title>CRUD Operations in PHP with PDO using Bootstrap</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<script src="js/jquery-1.12.4-jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href=""></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href=""></a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="wrapper">
<div class="container">
<div class="col-lg-12">
<?php
if(isset($errorMsg))
{
?>
<div class="alert alert-danger">
<strong>WRONG ! <?php echo $errorMsg; ?></strong>
</div>
<?php
}
if(isset($updateMsg)){
?>
<div class="alert alert-success">
<strong>UPDATE ! <?php echo $updateMsg; ?></strong>
</div>
<?php
}
?>
<center><h2>Edit Page</h2></center>
<form method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">Full Name</label>
<div class="col-sm-6">
<input type="textarea" name="txt_namasiswa" class="form-control" value="<?php echo $namasiswa; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Place of Birth</label>
<div class="col-sm-6">
<input type="text" name="txt_tempatlahir" class="form-control" value="<?php echo $tempatlahir; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Date of Birth</label>
<div class="col-sm-6">
<input type="date" name="tanggal" class="form-control" value="<?php echo $tgllahir; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Gender</label>
<div class="col-sm-6">
<Select name ="gender" class="form-control" id="gender" value="">
<option value="">- Select One -</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Height</label>
<div class="col-sm-6">
<input type="text" name="txt_tinggi" class="form-control" value="<?php echo $tinggi; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Weight</label>
<div class="col-sm-6">
<input type="text" name="txt_berat" class="form-control" value="<?php echo $berat; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Religion</label>
<div class="col-sm-6">
<Select name ="txt_agama" class="form-control" id="txt_agama" value="" >
<option value="">- Select One -</option>
<option value="Islam">Islam</option>
<option value="Catholic">Chatolic</option>
<option value="Protestant">Protenstant</option>
<option value="Hindu">Hinduism</option>
<option value="Buddhis">Buddishm</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Nationality</label>
<div class="col-sm-6">
<input type="text" name="txt_negara" class="form-control" value="<?php echo $negara; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Marital Status</label>
<div class="col-sm-6">
<Select name ="marital" class="form-control" id="marital" value="<?php echo $marital; ?>" >
<option value="">- Select One -</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Address</label>
<div class="col-sm-6">
<input type="textarea" name="txt_address" class="form-control" value="<?php echo $address; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Handphone Number</label>
<div class="col-sm-6">
<input type="text" name="txt_hpsiswa" class="form-control" value="<?php echo $hpsiswa; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Telephone Number</label>
<div class="col-sm-6">
<input type="textarea" name="txt_telpsiswa" class="form-control" value="<?php echo $telpsiswa; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email</label>
<div class="col-sm-6">
<input type="email" name="txt_email" class="form-control" value="<?php echo $email; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Last Education</label>
<div class="col-sm-6">
<Select name ="study" class="form-control" id="study" value="<?php echo $study; ?>">
<option value="">- Select One -</option>
<option value="Senior High School">Senior High School</option>
<option value="Vocational High School">Vocational High School</option>
<option value="Diploma I">Diploma I</option>
<option value="Diploma III">Diploma III</option>
<option value="Diploma IV">Diploma IV</option>
<option value="Bachelor">Bachelor</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">School Name</label>
<div class="col-sm-6">
<input type="text" name="txt_sekolah" class="form-control" value="<?php echo $sekolah; ?>" >
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">School Address</label>
<div class="col-sm-6">
<input type="text" name="txt_alamatsekolah" class="form-control" value="School Address<?php echo $sekolah; ?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Next of Kin</label>
<div class="col-sm-6">
<Select name ="family" class="form-control" id="family" required>
<option value="">- Select One -</option>
<option value="Mother">Mother</option>
<option value="Father">Father</option>
<option value="Sibling">Sibling</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Full Name</label>
<div class="col-sm-6">
<input type="text" name="txt_familyname" class="form-control" value="<?php echo $familyname; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Address</label>
<div class="col-sm-6">
<input type="text" name="txt_alamatortu" class="form-control" value="<?php echo $alamatfamily; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Handphone Number</label>
<div class="col-sm-6">
<input type="text" name="txt_hportu" class="form-control" value="<?php echo $hportu; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Telephone Number</label>
<div class="col-sm-6">
<input type="text" name="txt_tortu" class="form-control" value="<?php echo $tlportu; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Work Experience</label>
<div class="col-sm-6">
<input type="text" name="txt_experience" class="form-control" value="<?php echo $experience; ?>"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Company Name</label>
<div class="col-sm-6">
<input type="text" name="txt_perusahaan" class="form-control" value="<?php echo $perusahaan; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Start From</label>
<div class="col-sm-6">
<input type="date" name="txt_start" class="form-control" value="<?php echo $mulai; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">End of Contract</label>
<div class="col-sm-6">
<input type="date" name="txt_akhir" class="form-control" value="<?php echo $akhir; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Refferal Name</label>
<div class="col-sm-6">
<input type="text" name="txt_namaref" class="form-control" value="<?php echo $namaref; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Select Program</label>
<div class="col-sm-6">
<Select name ="txt_program" class="form-control" id="txt_program" value="<?php echo $hasilprogram; ?>" >
<option value="">- Select One -</option>
<option value="Regular">Regular</option>
<option value="Executive">Executive</option>
<option value="Isat">ISAT North Sumatra</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Select Job</label>
<div class="col-sm-6">
<Select name ="txt_job" class="form-control" id="txt_job" value="<?php echo $hasiljob; ?>">
<option value="">- Select One -</option>
<option value="Front Office">Front Office</option>
<option value="Cook">Cook</option>
<option value="Housekeeping">Housekeeping</option>
<option value="Waiter">Waiter/Waitress</option>
<option value="Bartender">Bartender/Barista</option>
<option value="Spa Therapist">Spa Therapist</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Select Class</label>
<div class="col-sm-6">
<Select name ="txt_class" class="form-control" id="txt_class" value ="<?php echo $hasilclass; ?>" >
<option value="">- Select One -</option>
<option value="Bali">Sea Bali</option>
<option value="Jakarta">Sea Jakarta</option>
<option value="Medan">Sea Medan</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Upload Foto</label>
<div class="col-sm-6">
<input type="file" name="images" class="form-control" value="Upload Your Photo" />
<p><img src="upload/<?php echo $image_file; ?>" height="100" width="100" /></p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9 m-t-15">
<input type="submit" name="btn_insert" class="btn btn-success " value="Insert">
<a href="index_admin.php" class="btn btn-danger">Cancel</a>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
mohon maaf bila koding tidak tersusun rapih
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban