<?php
error_reporting(0);
$host='localhost';
$user='root';
$pass='';
$conn=mysql_connect($host,$user,$pass);
mysql_select_db("coba",$conn)or die('gagal konek');
if($_POST['simpan'])
{
$NISN=$_POST['NISN'];
$Kode_KK=$_POST['Kode_KK'];
$Nama_siswa=$_POST['Nama_siswa'];
$Alamat_siswa=$_POST['Alamat_siswa'];
$Tgl_lahir=$_POST['Tgl_lahir'];
$Foto_siswa=$_POST['Foto_siswa'];
$foto=$_FILES["Foto_siswa"]["name"];
move_uploaded_file($_FILES["Foto_siswa"]["tmp_name"], "Foto_siswa/" . $_FILES["Foto_siswa"]["name"]);
if($foto<>"")
{
$sql=",Foto_siswa='".$foto."'";
}
$update="update siswa set Kode_KK='".$Kode_KK."',Nama_siswa='".$Nama_siswa."',Alamat_siswa='".$Alamat_siswa."',Tgl_lahir='".$Tgl_lahir."'".$sql." where NISN='".$NISN."'";
$hasil=mysql_query($update);
if(!$hasil)
{ echo $update; }
else
{ header('location:Siswa_show.php'); }
}
$id=$_GET['id'];
$show="select * from siswa where NISN='".$id."'";
$result=mysql_query($show);
$data=mysql_fetch_array($result);
?>
<form method='post' enctype='multipart/form-data'>
<table>
<tr>
<td>NISN</td>
<td>: <input type='text' name='NISN' maxlength='20' value='<?php echo $data['NISN']; ?>'></td>
</tr>
<tr>
<td>Kode KK</td>
<td>: <input type='text' name='Kode_KK' maxlength='20' value='<?php echo $data['Kode_KK']; ?>'></td>
</tr>
<tr>
<td>Nama Siswa</td>
<td>: <input type='text' name='Nama_siswa' maxlength='20' value='<?php echo $data['Nama_siswa']; ?>'></td>
</tr>
<tr>
<td>Alamat Siswa</td>
<td>: <input type='text' name='Alamat_siswa' maxlength='20' value='<?php echo $data['Alamat_siswa']; ?>'></td>
</tr>
<tr>
<td>Tgl Lahir</td>
<td>: <input type='text' name='Tgl_lahir' maxlength='20' value='<?php echo $data['Tgl_lahir']; ?>'></td>
</tr>
<tr>
<td>Foto Siswa</td>
<td>: <input type='file' name='Foto_siswa' maxlength='100' value='<?php echo $data['Foto_siswa']; ?>'></td>
</tr>
<tr>
<td colspan='2'><input type='submit' name='simpan' value='SIMPAN'></td>
</tr>
</table>
Contoh Code Edit PHP(Dengan Foto)
Reviewed by Syafriansyah Muhammad
on
2/27/2015
Rating:
Tidak ada komentar: