KONEKSI.PHP
<?php
$host="localhost";
$user="root";
$password="";
$database="db_lomba";
$koneksi=mysql_connect($host,$user,$password) or die (mysql_error());
$sqldb=mysql_select_db($database,$koneksi) or die (mysql_error());
?>
INDEX.PHP
<?php
include "koneksi.php";
if(isset($_POST['simpan'])){
$nama_team = $_POST['nama_team'];
$anggota_team = $_POST['anggota_team'];
$universitas_asal = $_POST['universitas_asal'];
$tingkat = $_POST['tingkat'];
$materi_lomba = $_POST['materi_lomba'];
$contact_person = $_POST['contact_person'];
$q = "INSERT INTO tb_daftar
(
nama_team,
anggota_team,
universitas_asal,
tingkat,
materi_lomba,
contact_person
)
VALUES
(
'$nama_team',
'$anggota_team',
'$universitas_asal',
'$tingkat',
'$materi_lomba',
'$contact_person'
)";
$r = mysql_query($q) or die (mysql_error());
if($r){
header("location:tampil.php");
}
else{
$msg = "Data tidak berhasil disimpan";
}
}
?>
<form action="index.php" method="POST">
<fieldset>
<legend>FORMULIR PENDAFTARAN LOMBA</legend>
<table>
<?php
/*if($msg!=''){
echo "$msg";
}*/
?>
<tr>
<td>nama_team</td><td> : </td>
<td><input type="text" name="nama_team" placeholder=""/></td>
</tr>
<tr>
<td>anggota_team</td><td> : </td>
<td><input type="text" name="anggota_team" placeholder=""/></td>
</tr>
<tr>
<td>universitas_asal</td><td> : </td>
<td><input type="text" name="universitas_asal"></td>
</tr>
<tr>
<td>tingkat</td><td> : </td>
<td><select name="tingkat"><option value="D1"> D1</option>
<option value="D3"> D3</option>
<option value="S1"> S1</option>
<option value="S2"> S2</option>
<option value="S3"> S3</option>
</select>
</td>
</tr>
<tr>
<td>materi_lomba</td><td> : </td>
<td>
<input type="radio" name="materi_lomba" value="WEB PROGRAMING"> WEB PROGRAMING
<input type="radio" name="materi_lomba" value="WEB DESIGN"> WEB DESIGN
</td>
</tr>
<tr>
<td>contact_person</td><td> : </td>
<td><input type="text" name="contact_person" placeholder=""/></td>
</tr>
<tr>
<td><input type="submit" name="simpan" value="simpan"/>
<input type="submit" name="reset" value="reset"/>
</td>
</tr>
</table>
</fieldset>
</form>
TAMPIL.PHP
<?php
include "koneksi.php";
$sql = "SELECT * FROM tb_daftar";
$res=mysql_query($sql,$koneksi) or die(mysql_error());
?>
<table border='1' width='100%' cellpadding='3' cellspacing='0' style='border-collapse:collapse'>
<tr align='center'>
<th width='3%'>No.</th>
<th width='20%'>Nama_Team</th>
<th width='10%'>Anggota_Team</th>
<th width='10%'>Universitas_Asal</th>
<th width='10%'>Tingkat</th>
<th width='10%'>Materi_Lomba</th>
<th width='10%'>Contact_Person</th>
<th width='10%'>Edit</th>
<th width='10%'>Hapus</th>
</tr>
<?php
$i = 1;
while ($data = mysql_fetch_array($res)){
if($i%2==0)$bg='#CCCCCC';
else $bg = '#FFFFFF';
echo "<tr bgcolor = '".$bg."'>
<td align='center'>".$i."</td>
<td>".$data["nama_team"]."</td>
<td>".$data["anggota_team"]."</td>
<td>".$data["universitas_asal"]."</td>
<td>".$data["tingkat"]."</td>
<td>".$data["materi_lomba"]."</td>
<td>".$data["contact_person"]."</td>
<td align='center'><a href='edit.php?No=".$data[0]."'>Edit</a></td>
<td align='center'><a href='hapus.php?No=".$data[0]."'>Hapus</a></td>
</tr>";
$i++;
}
?>
</table>
<a href='index.php?'>Tambah Baru</a></td>
EDIT.PHP
<?php
include "koneksi.php";
$No=$_GET['No'];
$q="SELECT * FROM tb_daftar WHERE No ='$No'";
$r=mysql_query($q) or die ($q);
$d=mysql_fetch_array($r);
if(isset($_POST['simpan'])){
$nama_team = $_POST['nama_team'];
$anggota_team = $_POST['anggota_team'];
$universitas_asal = $_POST['universitas_asal'];
$tingkat = $_POST['tingkat'];
$materi_lomba = $_POST['materi_lomba'];
$contact_person = $_POST['contact_person'];
$q="UPDATE tb_daftar SET nama_team = '$nama_team',
anggota_team='$anggota_team',
universitas_asal='$universitas_asal',
tingkat='$tingkat',
materi_lomba='$materi_lomba',
contact_person='$contact_person'
WHERE No = '$No'";
$r=mysql_query($q) or die(mysql_error());
if($r){
header("location:tampil.php");
}
else{
$msg = "Data tidak bisa diedit";
}
}
?>
<form action="edit.php?No=<?php echo $No;?>" method="POST">
<legend>FORMULIR PENDAFTARAN LOMBA</legend>
<table>
<?php
/*if($msg!=''){
echo "$msg";
}*/
?>
<tr>
<td>nama_team</td><td> : </td>
<td><input type="text" name="nama_team" value='<?php echo $d[1];?>'></td>
</tr>
<tr>
<td>anggota_team</td><td> : </td>
<td><input type="text" name="anggota_team" value='<?php echo $d[2];?>'></td>
</tr>
<tr>
<td>universitas_asal</td><td> : </td>
<td><input type="text" name="universitas_asal" value='<?php echo $d[3];?>'></td>
</tr>
<tr>
<td>tingkat</td><td> : </td>
<td><select name="tingkat"><option value="D1" <?php if($d[4]=="D1") { echo"selected='selected'";}?>> D1</option>
<option value="D3" <?php if($d[4]=="D3") { echo"selected='selected'";}?>> D3</option>
<option value="S1" <?php if($d[4]=="S1") { echo"selected='selected'";}?>> S1</option>
<option value="S2" <?php if($d[4]=="S2") { echo"selected='selected'";}?>> S2</option>
<option value="S3" <?php if($d[4]=="S3") { echo"selected='selected'";}?>> S3</option>
</select>
</td>
</tr>
<tr>
<td>materi_lomba</td><td> : </td>
<td>
<input type="radio" name="materi_lomba" value="Web Programing" <?php if($d[5]=="Web Programing") { echo "checked='checked'";}?>> Web Programing
<input type="radio" name="materi_lomba" value="Web Design" <?php if($d[5]=="Web Design") { echo "checked='checked'";}?>> Web Design
</td>
</tr>
<tr>
<td>contact_person</td><td> : </td>
<td><input type="text" name="contact_person" value='<?php echo $d[6];?>'></td>
</tr>
<tr>
<td><input type="submit" name="simpan" value="Edit"/>
<input type="submit" name="reset" value="Reset"/>
</td>
</tr>
</table>
</form>
HAPUS.PHP
<?php
include "koneksi.php";
$id = $_GET['No'];
$q="DELETE FROM db_lomba.tb_daftar WHERE No='$id'";
$r=mysql_query($q) or die(mysql_error());
header("location:tampil.php");
?>
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar