I am making edit data form. Then in edit form, there are 3 input file type (image). So the problem is, when i updated 1 file on one of the input file type, the other input file type updated as well and unlink the previous data so in database, the coloum is empty. So i want to make this edit form, when i update 1 file, the other file do not get change as well.. only the one that being updated and the other keep the previous file. All helps and answer would be much appreciated.. Thankyou Here is the code for edithotel.php
<?php
include "koneksi.php";
$id=$_POST['idhotel'];
$namahotel=$_POST['namahotel'] ;
$alamat=$_POST['alamat'] ;
$notelp=$_POST['notelp'] ;
$gambar1=$_FILES['gambar1']['tmp_name'];
$gambar2=$_FILES['gambar2']['tmp_name'];
$gambar3=$_FILES['gambar3']['tmp_name'];
$nama_file1 = $_FILES['gambar1']['name'];
$nama_file2 = $_FILES['gambar2']['name'];
$nama_file3 = $_FILES['gambar3']['name'];
$tempat_gambar1= 'file/hotel/gambar1/'.$nama_file1;
$tempat_gambar2= 'file/hotel/gambar2/'.$nama_file2;
$tempat_gambar3= 'file/hotel/gambar3/'.$nama_file3;
$latitude=$_POST['latitude'] ;
$longitude=$_POST['longitude'] ;
$qr=mysql_query("select * FROM tbhotel WHERE idhotel='$id'");
$r=mysql_fetch_array($qr);
$tempat_foto1 = 'file/hotel/gambar1/'.$r['gambar1'];
$tempat_foto2 = 'file/hotel/gambar2/'.$r['gambar2'];
$tempat_foto3 = 'file/hotel/gambar3/'.$r['gambar3'];
//$ccc = mysql_query("SELECT * FROM tbhotel WHERE idhotel='$id' ");
//$z = mysql_fetch_array($ccc);
//upload gambar
if (isset($_POST['simpan'])){
if($gambar1 != 'kosong'){
$d1 = 'file/hotel/gambar1/'.$r['gambar1'];
unlink ("$d1");
move_uploaded_file ($_FILES['gambar1']['tmp_name'], "file/hotel/gambar1/".$nama_file1);
//echo '<script>alert("DATA BBB DIUBAH");location="hotel.php";</script>';
$sql = mysql_query("UPDATE tbhotel SET namahotel ='$namahotel', alamat = '$alamat', notelp = '$notelp' , gambar1='$nama_file1', latitude ='$latitude' , longitude ='$longitude' where idhotel='$id'") or die (mysql_error());
}
if($gambar2 != 'kosong'){
$d2 = 'file/hotel/gambar2/'.$r['gambar2'];
unlink ("$d2");
move_uploaded_file ($_FILES['gambar2']['tmp_name'], "file/hotel/gambar2/".$nama_file2);
$sql2 = mysql_query("UPDATE tbhotel SET namahotel ='$namahotel', alamat = '$alamat', notelp = '$notelp' , gambar2='$nama_file2', latitude ='$latitude' , longitude ='$longitude' where idhotel='$id'") or die (mysql_error());
}
if($gambar3 != 'kosong'){
$d3 = 'file/hotel/gambar3/'.$r['gambar3'];
unlink ("$d3");
move_uploaded_file ($_FILES['gambar3']['tmp_name'], "file/hotel/gambar3/".$nama_file3);
$sql3 = mysql_query("UPDATE tbhotel SET namahotel ='$namahotel', alamat = '$alamat', notelp = '$notelp' , gambar3='$nama_file3', latitude ='$latitude' , longitude ='$longitude' where idhotel='$id'") or die (mysql_error());
}
if ($sql) {
//jika berhasil tampil ini
echo '<script>alert("DATA BERHASIL DIUBAH");location="hotel.php";</script>';
} else {
// jika gagal tampil ini
echo '<script>alert("DATA GAGAL DIUBAH");location="formedithotel.php";</script>';
}
}
?>
and here is the code for editform.html
<form name="edithotel" enctype="multipart/form-data" action="edithotel.php" method="post" enctype="multipart/form-data" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12" for="last-name">Nama Hotel</label>
<div class="col-lg-12">
<input type="text" id="namahotel" name="namahotel" value="<?php echo $result['namahotel']; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12" for="last-name">Alamat</label>
<div class="col-lg-12">
<textarea class="form-control" rows="5" id="alamat" name="alamat" ><?php echo $result['alamat']; ?></textarea>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12" for="last-name">No Telp</label>
<div class="col-lg-12">
<input type="text" id="notelp" name="notelp" value="<?php echo $result['notelp']; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12">Gambar 1</label><br>
<div class="col-md-6 col-sm-6 col-xs-12">
<img src="file/hotel/gambar1/<?php echo $result['gambar1']; ?>" width='80' height='60'/>
<input type="file" id="gambar1" name="gambar1" value="kosong">
</div>
</div><br>
<div class="form-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12">Gambar 2</label><br>
<div class="col-md-6 col-sm-6 col-xs-12">
<img src="file/hotel/gambar2/<?php echo $result['gambar2']; ?>" width='80' height='60'/>
<input type="file" id="gambar2" name="gambar2" value="kosong">
</div>
</div><br>
<div class="form-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12">Gambar 3</label><br>
<div class="col-md-6 col-sm-6 col-xs-12">
<img src="file/hotel/gambar3/<?php echo $result['gambar3']; ?>" width='80' height='60'/>
<input type="file" id="gambar3" name="gambar3" value="kosong">
</div>
</div><br>
<div class="form-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12" for="last-name">Latitude</label>
<div class="col-lg-12">
<input type="text" id="latitude" name="latitude" value="<?php echo $result['latitude']; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12" for="last-name">Longitude</label>
<div class="col-lg-12">
<input type="text" id="longitude" name="longitude" value="<?php echo $result['longitude']; ?>">
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<button type="submit" name="simpan" class="btn btn-success">Update</button>
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire