<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Siswa</title>
</head>
<body>
<?php
include("koneksi.php");
mysql_select_db("data_siswa");
if($proses){
if($nis==""){
echo"NIS belum terisi";
}elseif ($nama==""){
echo"Nama belum terisi";
}elseif ($kelas==""){
echo"Kelas belum terisi";
}elseif ($jurusan==""){
echo"Jurusan belum terisi";
}else{
mysql_query("INSERT INTO tabel_siswa(nis,nama,kelas,jurusan) values ('$nis','$nama','$kelas','$jurusan')");
echo"<p> Data sukses ditambahkan </p>";
echo"<p> <a href=\"form_siswa.php\" target=\"_parent\">Tambah Data</a>, <a href=\"tampil_siswa.php\">Lihat Data</a></p>";
}
}else
{
?>
<div align="center">
<p>FORM DATA SISWA</p>
<form id="form1" name="form1" method="post" action="form_siswa.php">
<table width="100%" border="2" cellspacing="2" cellpadding="2">
<tr>
<td width="116" bgcolor="#CCCCCC">NIS</td>
<td width="362" bgcolor="#CCCCCC"><label for="nis"></label>
<input type="text" name="nis" id="nis" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">NAMA</td>
<td bgcolor="#CCCCCC"><label for="nama"></label>
<input name="nama" type="text" id="nama" size="50" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">KELAS</td>
<td bgcolor="#CCCCCC"><label for="kelas"></label>
<input name="kelas" type="text" id="kelas" size="20" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">JURUSAN</td>
<td bgcolor="#CCCCCC"><label for="jurusan"></label>
<input name="jurusan" type="text" id="jurusan" size="50" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> </td>
<td bgcolor="#CCCCCC"><input type="submit" name="proses" id="proses" value="PROSES" /></td>
</tr>
</table>
</form>
<p><a href="tampil_siswa.php">Lihat Data</a> | <a href="edit_siswa.php">Edit Data</a></p>
</div>
<?
}
?>
</body>
</html>
<?php
function get_menu($data, $parent = 0) {
static $i = 1;
$tab = str_repeat("\t\t", $i);
if (isset($data[$parent])) {
$html = "\n$tab<ul>";
$i++;
foreach ($data[$parent] as $v) {
$child = get_menu($data, $v->id);
$html .= "\n\t$tab<li>";
$html .= '<a href="'.$v->url.'">'.$v->title.'</a>';
if ($child) {
$i--;
$html .= $child;
$html .= "\n\t$tab";
}
$html .= '</li>';
}
$html .= "\n$tab</ul>";
return $html;
} else {
return false;
}
}
mysql_connect('localhost', 'root', '');
mysql_select_db('tes');
$result = mysql_query("SELECT * FROM menu ORDER BY menu_order");
while ($row = mysql_fetch_object($result)) {
$data[$row->parent_id][] = $row;
}
$menu = get_menu($data);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sistem Informasi OBC</title>
<link rel="stylesheet" type="text/css" href="jquerycssmenu.css" />
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquerycssmenu.js"></script>
<style type="text/css">
body { font: 11px Tahoma, sans-serif; margin: 0; padding: 0; }
a { color: #3150a9; text-decoration: none; }
#content { padding: 10px; margin: 15px; border: 1px solid #ccc; width: 1350px; background: #fafafa; }
</style>
</head>
<body>
<align="center"><img src="telkom.jpg" height="150" width="1350"></align>
<div id="myjquerymenu" class="jquerycssmenu">
<?php echo $menu; ?>
<br style="clear: left" />
</div>
<div id="content">
<form name="form1" action="save-gallery2.php" method="post" enctype="multipart/form-data">
<pre>
Nama :<input type="text" name="nama" id="nama"/><br/>
Tempat Tanggal Lahir :<input type="text" name="tanggal">Format yyyy-mm-dd<br/>
Jenis Kelamin :<select name='gender'>
<option value='....'>pilih kebawah</option>
<option value='Pria'>Pria</option>
<option value='Wanita'>Wanita</option>
</select><br/>
Pendidikan Terakhir :<select name='pendidikan'>
<option value='....'>pilih kebawah</option>
<option value='SMA'>SMA</option>
<option value='D3'>D3</option>
<option value='S1'>S1</option>
<option value='S2'>S2</option>
<option value='S3'>S3</option>
</select></br>
Alamat :<input typr="text" name="alamat" id="alamat"/></br>
File :<input type="file" name="file" id="file"/><br/>
Deskripsi :<textarea name="deskripsi" id="deskripsi"></textarea><br/>
<input type="submit" name="save" value="Upload"/></pre>
</form>
</div>
</body>
</html>
<?php
//koneksi ke database
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('galeri');
//upload file
if(!empty($_FILES) && $_FILES['file']['size'] > 0 && $_FILES['file']['error'] == 0){
$fileName = $_FILES['file']['name'];
$move = move_uploaded_file($_FILES['file']['tmp_name'], 'images/'.$fileName);
if($move){
//simpan deskripsi dan nama file ke database
$sql = "insert into foto (nama_file, deskripsi, nama, alamat, gender, pendidikan, tanggal) values
('$fileName', '".$_POST['deskripsi']."', '".$_POST['nama']."', '".$_POST['alamat']."', '".$_POST['gender']."', '".$_POST['pendidikan']."', '".$_POST['tanggal']."')";
$hasil = mysql_query($sql);
?><script language='javascript'>window.alert('Data Sukses');document.location='sales.php'</script><?php
}else{
?><script language='javascript'>window.alert('Data gagal');document.location='sales.php'</script><?php
echo mysql_error();
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Siswa</title>
</head>
<body>
<?php
include("koneksi.php");
mysql_select_db("data_siswa");
if($proses){
if($nis==""){
echo"NIS belum terisi";
}elseif ($nama==""){
echo"Nama belum terisi";
}elseif ($kelas==""){
echo"Kelas belum terisi";
}elseif ($jurusan==""){
echo"Jurusan belum terisi";
}else{
if($_FILES['foto']['size'] > 0 && $_FILES['foto']['error'] == 0){
$foto = $_FILES['foto']['name'];
//misal foto ditaruh di folder foto/
$move = move_uploaded_file($_FILES['foto']['tmp_name'], 'foto/'.$foto);
if(!$move){//gagal upload foto
$foto = '';
}
}
//tambahkan satu kolom foto di tabel siswa
mysql_query("INSERT INTO tabel_siswa(nis,nama,kelas,jurusan,foto) values ('$nis','$nama','$kelas','$jurusan','$foto')");
echo"<p> Data sukses ditambahkan </p>";
echo"<p> <a href=\"form_siswa.php\" target=\"_parent\">Tambah Data</a>, <a href=\"tampil_siswa.php\">Lihat Data</a></p>";
}
}else
{
?>
<div align="center">
<p>FORM DATA SISWA</p>
<form id="form1" name="form1" method="post" action="form_siswa.php" enctype="multipart/form-data">
<table width="100%" border="2" cellspacing="2" cellpadding="2">
<tr>
<td width="116" bgcolor="#CCCCCC">NIS</td>
<td width="362" bgcolor="#CCCCCC"><label for="nis"></label>
<input type="text" name="nis" id="nis" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">NAMA</td>
<td bgcolor="#CCCCCC"><label for="nama"></label>
<input name="nama" type="text" id="nama" size="50" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">KELAS</td>
<td bgcolor="#CCCCCC"><label for="kelas"></label>
<input name="kelas" type="text" id="kelas" size="20" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">JURUSAN</td>
<td bgcolor="#CCCCCC"><label for="jurusan"></label>
<input name="jurusan" type="text" id="jurusan" size="50" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Foto</td>
<td bgcolor="#CCCCCC"><input name="foto" type="file" id="foto"/></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> </td>
<td bgcolor="#CCCCCC"><input type="submit" name="proses" id="proses" value="PROSES" /></td>
</tr>
</table>
</form>
<p><a href="tampil_siswa.php">Lihat Data</a> | <a href="edit_siswa.php">Edit Data</a></p>
</div>
<?
}
?>
</body>
</html>
Ref: http://www.myphptutorials.com/tutorials/20/upload-gambar-dengan-php