Bahan DataBase WebHost Work 100%

| Jumat, 02 Februari 2018

Edit : 

<?php
include "koneksi.php";
if (isset($_GET['nis'])) {
$nis = $_GET['nis'];
} else {
die ("Error. No nis Selected! ");
}
$query = "SELECT * FROM siswa WHERE nis='$nis'";
$sql = mysql_query ($query);
$hasil = mysql_fetch_array ($sql);
$nis = $hasil['nis'];
$nama = stripslashes ($hasil['nama']);
$alamat = stripslashes ($hasil['alamat']);
$kelas = stripslashes ($hasil['kelas']);
$nohp = stripslashes ($hasil['nohp']);
$namafoto = stripslashes ($hasil['namafoto']);
//proses edit Siswa
if (isset($_POST['Edit'])) {
$nis = $_POST['hnis'];
$nama = addslashes (strip_tags ($_POST['nama']));
$alamat = addslashes (strip_tags ($_POST['alamat']));
$nohp = addslashes (strip_tags ($_POST['nohp']));
$kelas = addslashes (strip_tags ($_POST['kelas']));
$namafoto = $_FILES['foto']['name'];
if (strlen($namafoto)>0) {
//upload
if (is_uploaded_file($_FILES['foto']['tmp_name'])) {
move_uploaded_file ($_FILES['foto']['tmp_name'], "images/".$namafoto);
mysql_query ("UPDATE pegawai SET namafoto='$namafoto' WHERE
nip='$nip'");
}
}
//update data
$query = "UPDATE siswa SET nama='$nama',nohp='$nohp',kelas='$kelas',
alamat='$alamat',namafoto='$namafoto' WHERE nis='$nis'";
$sql = mysql_query ($query);
if ($sql) {
echo "<h2><font color=blue>Data siswa telah berhasil diedit</font></h2>";
} else {
echo "<h2><font color=red>Data siswa gagal diedit</font></h2>";
}
}
?>
<div id="content">
<h2>Edit Data siswa</h2>
<?php
echo" <FORM ACTION='' METHOD='POST' NAME='input' enctype='multipart/formdata'>
<table cellpadding='0' cellspacing='0' border='0' width='700'>
<tr>
<td width='200'>nis</td> <td>: <b>$nis</b></td>
</tr>
<tr>
<td>Nama</td> <td>: <input type='text' name='nama' size='30' maxlength='30'
value='$nama'></td>
</tr>
<tr>
<td>Alamat</td> <td>: <textarea name='alamat' cols='40'
rows='5'>$alamat</textarea></td>
</tr>
<tr>
<td>NoHp</td> <td>: <input type='text' name='nohp' size='12'
maxlength='12'value='$nohp'></td>
</tr>
<tr> <td>kelas</td> <td>: <select name='kelas'> <option value='$kelas'>$kelas
<option value='X'>X
<option value='XI'>XI
<option value='XII'>XII
</select></td>
</tr>
<tr>
<td>Foto</td>
<td>: <input type='file' name='foto'/> Foto: $namafoto</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;&nbsp;
<input type='hidden' name='hnis' value='$nis'>
<input type='submit' name='Edit' value='Edit Data'>&nbsp;
<input type='reset' name='reset' value='Reset'></td>
</tr>
</table>
</FORM>"
?>
</div>

Hapus:


 <?php
include "koneksi.php";
if (isset($_GET['nis'])) {
$nis = $_GET['nis'];
} else {
die ("Error. No nis Selected! ");
}
?>
<div id="content">
<?php
if (!empty($nis) && $nis != "") {
$query = "DELETE FROM siswa WHERE nis='$nis'";
$sql = mysql_query ($query);
if ($sql) {
echo "<h2><font color=blue>Data siswa telah berhasil dihapus</font></h2>";
} else {
echo "<h2><font color=red>Data siswa gagal dihapus</font></h2>";
}
echo "Klik <a href='index.php?page=tampil'>di sini</a> untuk kembali ke halaman data
siswa";
} else {
die ("Access Denied");
}
?>
</div>


 Indek :


 <html>
<head>
<title>Sistem akademik</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main_container">
<div id="header">
<h1>Sistem akademik</h1>
</div>
<div id="navigation">
<a href="index.php">Home</a>
<a href="index.php?page=input">Input Data Siswa</a>
<a href="index.php?page=tampil">Tampil Data Siswa</a>
</div>
<?php
$page = (isset($_GET['page']))? $_GET['page'] : "main";
switch ($page) {
case 'input': include "input.php"; break;
case 'edit' : include "edit.php"; break;
case 'tampil': include "tampil.php"; break;
case 'delete' : include "hapus.php"; break;
case 'foto' : include "foto.php"; break;
case 'main' :
default : include 'utama.php';
}
?>
<div id="footer">&copy; 2014 <a href="">Faza Amri Insani</a> | Design By <a href="">Faza Amri Insani</a>
</div>
</div>
</body>
</html>


 Input :


<?php
include "koneksi.php";
//proses input siswa
if (isset($_POST['Input'])) {
$nis = addslashes (strip_tags ($_POST['nis']));
$nama = addslashes (strip_tags ($_POST['nama']));
$alamat = addslashes (strip_tags ($_POST['alamat']));
$nohp = addslashes (strip_tags ($_POST['nohp']));
$kelas = addslashes (strip_tags ($_POST['kelas']));
$namafoto = $_FILES['foto']['name'];
if (strlen ($nis) != 10) {
die ("nis harus 10 digit");
}
if (strlen($namafoto)>0) {
//upload
if (is_uploaded_file($_FILES['foto']['tmp_name'])) {
move_uploaded_file ($_FILES['foto']['tmp_name'], "images/".$namafoto);
}
}
//insert ke tabel
$query = "INSERT INTO siswa
VALUES('$nis','$nama','$alamat','$nohp','$kelas','$namafoto')";
$sql = mysql_query ($query) or die (mysql_error());
if ($sql) {
echo "<h2><font color=blue>Data siswa telah berhasil ditambahkan</font></h2>";
} else {
echo "<h2><font color=red>Data siswa gagal ditambahkan</font></h2>";
}
}
?>
<div id="content">
<h2>Input Data siswa</h2>
<FORM ACTION="" METHOD="POST" NAME="input" enctype="multipart/formdata">
<table cellpadding="0" cellspacing="0" border="0" width="700">
<tr>
<td width="200">nis</td>
<td>: <input type="text" name="nis" size="15" maxlength="10"></td>
</tr>
<tr>
<td>Nama</td>
<td>: <input type="text" name="nama" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Alamat</td>
<td>: <textarea name="alamat" cols="40" rows="5"></textarea></td>
</tr>
<tr>
<td>NoHp</td>
<td>: <input type="text" name="nohp" size="12" maxlength="12"></td>
</tr>
<tr>
<td>kelas</td>
<td>: <select name="kelas">
<option value="X">X
<option value="XI">XI
<option value="XII">XII
</select></td>
</tr>
<tr>
<td>Foto</td>
<td>: <input type="file" name="foto"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;&nbsp;<input type="submit" name="Input" value="Input
Data">&nbsp;
<input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</FORM>
</div> 


 Koneksi :


<?php
$hostname = "localhost";
$username = "id2850036_akademik";
$password = "none";
$database = "id2850036_akademik";
$connect  = mysql_connect($hostname, $username, $password);
$db       = mysql_select_db($database);
if($connect) {
    echo 'Berhasil koneksi ke database';

    if($db) {
        echo ' dan database ditemukan';
    }
    else {
        echo ' namun database tidak berhasil ditemukan';
    }
}
else {
    echo 'Gagal terhubung ke database';
}


  Tampil :


 <div id="content">
<h2>Data Siswa</h2>
<?php
include "koneksi.php";
// ----- perintah SQL dimasukkan ke dalam variable string
$sqlstr="select * from siswa order by nis";
$result = mysql_query ($sqlstr);
echo("<table id='tabel'>");
echo("<tr>
<td bgcolor=#CCCCCC width='5%'>No</td>
<td bgcolor=#CCCCCC width='10%'>NIS</td>
<td bgcolor=#CCCCCC width='20%'>Nama</td>
<td bgcolor=#CCCCCC width='30%'>Alamat</td>
<td bgcolor=#CCCCCC width='15%'>No Hp</td>
<td bgcolor=#CCCCCC width='10%'>Kelas</td>
<td bgcolor=#CCCCCC >action</td></tr>");
// ------ ambil isi masing-masing record
$no=1;
while ($row = mysql_fetch_array ($result))
{
// ----- mengambil isi setiap kolom
$nis=$row[nis];
$nama=$row[nama];
$alamat=$row[alamat];
$nohp=$row[nohp];
$kelas=$row[kelas];
$warna = ($no%2==1)?'#ffffff':'#efefef';
// ------ menampilkan di layar browser
echo("<tr bgcolor ='$warna'>
<td bgcolor=#FFFFFF>$no</td>
<td bgcolor=#FFFFFF>$nis</td>
<td bgcolor=#FFFFFF>$nama</td>
<td bgcolor=#FFFFFF>$alamat</td>
<td bgcolor=#FFFFFF>$nohp</td>
<td bgcolor=#FFFFFF>$kelas</td>
<td bgcolor=#FFFFFF><a href='index.php?page=foto&nis=$nis'>Foto</a><br/>
<a href='index.php?page=edit&nis=$nis'>Edit</a><br/>
<a href='index.php?page=delete&nis=$nis'>Delete</a></td></tr>");
$no++;
}
echo("</table>");
?>
</div>


 Utama :


<div id="content">
<h2>Selamat Datang di Sistem AKADEMIK SMA N 1 BANYUDONO</h2>
<p>Sistem AKADEMIK ini dibuat untuk matakuliah Pemrograman WEB di
TKJ SMA N 1 BANYUDONO</a></p>
<p>Dalam ini, Anda dapat <a href="index.php?page=input">menginput</a> data siswa,
<a href="index.php?page=tampil">melihat</a> data siswa,
dan mengedit serta delete data siswa</p>
<p>Have a nice day ......!</p>
</div> 

0 komentar:

Posting Komentar

Next Prev
▲Top▲