<?php
$kata ="LABSI 2013";
$angka1=20;
$angka2=10;
echo 'echo dengan kutipan satu :| $kata | $angka1 | $angka2 | $angka1 * $angka2 <br/>';
echo "echo dengan kutipan dua :| $kata | $angka1 | $angka2 | $angka1 * $angka2 <br/>";
echo $kata;
echo "<br/>";
echo $angka1*$angka2;
echo "</br/>";
echo "$angka1*$angka2=".$angka1*$angka2."<br/>";
?>
bilangan ganjil genap
<?php
$bilangan=20;
if ($bilangan %2 == 0)
{
echo "$bilangan adalah bilangan genap";
}
else
{
echo "$bilangan adalah bilangan ganji";
}
?>
bintang
<form action='' method='post'>
Masukan Angka <input type='text' name='angka'>
<input type='submit' name='kirim' value='kirim'>
</form>
<?php
if(isset ($_POST['kirim'])){
$angka=$_POST['angka'];
for($i=1; $i<=$angka; $i++) {
for($d=1; $d<=$i; $d++) {
echo "*";
}
echo "<br />";
}
}
?>
menu 1
<form action='2.php' method='post'>
<table align='center' colspan='10'>
<tr>
<th colspan='2'>Input Data Diri</th>
</tr>
<tr>
<td>Nama</td>
<td><input type='text' name='nama'></td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td>
<input type='radio' name='jkel' value='pria'>Pria
<input type='radio' name='jkel' value='wanita'>Wanita
</td>
</tr>
<tr>
<td>Agama</td>
<td>
<select name='agama'>
<option value='Islam'>Islam</option>
<option value='Katolik'>Katolik</option>
<option value='Protestan'>Protestan</option>
<option value='Hindu'>Hindu</option>
<option value='Budha'>Budha</option>
</select>
</td>
</tr>
<tr>
<td>Alamat</td>
<td><textarea name='alamat'></textarea></td>
</tr>
<tr>
<th colspan='2'><input type='submit' name='kirim' value='kirim'></th>
</tr>
</table>
</form>
menu 2
<?php
$nama=$_POST['nama'];
$jkel=$_POST['jkel'];
$agama=$_POST['agama'];
$alamat=$_POST['alamat'];
echo"
<table align='center' width='200' border='1'>
<tr>
<th colspan='2'>Data Diri</th>
</tr>
<tr>
<td width='100'>Nama</td>
<td>$nama</td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td>$jkel</td>
</tr>
<tr>
<td>Agama</td>
<td>$agama</td>
</tr>
<tr>
<td>Alamat</td>
<td>$alamat</td>
</table>";
?>
login
<?php session_start(); ?>
<form action='' method='post'>
<table align='center'>
<tr>
<th colspan='2'>Login Admin</th>
</tr>
<td>Username</td>
<td><input type='text' name='user' /></td>
</tr>
<tr>
<td>Password</td>
<td><input type='password' name='pass' /></td>
</tr>
<tr>
<th colspan='2'><input type='submit' value='login' name='login'</th>
</tr>
</table>
</form>
<?php
if (isset($_POST['login'])){
$username = $_POST['user'];
$password = $_POST['pass'];
if ( ($username == "akramin") && ($password == "akramin")){
$_SESSION['login'] = $username;
echo "<center>Login Sukses,<a href='input.php'>Silahkan lanjut ke menu input</a></center>";}
else{
echo "<center>username atau password salah</center>";}
}
?>
input
<?php
session_start();
if (!isset($_SESSION['login'])){
echo "<center><a href='login.php'>Silahkan login terlebih dahulu</a></center>";}
else{
echo "
<center>
selamat datang,".$_SESSION['login']."<br/>
<a href='input.php'>Input data | <a href='view.php'>lihat data | <a href='logout.php'>logout</a>
</center>
<form action='' method='post'>
<table align='center' border='1'>
<tr>
<th colspan='2'>Input Data Mahasiswa</th>
</tr>
<tr>
<td>Npm</td>
<td><input type='text' name='npm'></td>
</tr>
<tr>
<td width='70'>Nama</td>
<td><input type='text' name='nama'></td>
</tr>
<tr>
<td>Kelas</td>
<td><input type='text' name='kelas'></td>
</tr>
<tr>
<th colspan='2'><input type='submit' name='simpan' value='simpan'</th>
</tr>
</table>
</form>
";
if (isset($_POST['simpan'])){
$line= count (@$_SESSION['data_mhs']);
if($line){
foreach(@$_SESSION['data_mhs'] as $line => $data){
if (isset ($_POST['simpan'])){
$line +=1;
}
}
}
$_SESSION['data_mhs'][$line]['npm'] = $_POST['npm'];
$_SESSION['data_mhs'][$line]['nama'] = $_POST['nama'];
$_SESSION['data_mhs'][$line]['kelas'] = $_POST['kelas'];
echo "<center>data berhasil ditambah</center>";
}
}
?>
logout
<?php
session_start();
unset($_SESSION['login']);
echo "<center>anda telah berhasil logout, <a href='login.php'>Kembali ke menu login</a></center>";
?>
delete
<?php
session_start();
$del_line = $_GET['line'];
foreach($_SESSION['data_mhs'] as $line => $data){
if($line == $del_line){
unset($_SESSION['data_mhs'][$line]);
echo "<center>data berhasil dihapus</center>";
echo "<center><a href='view.php'>back</a></center>";
}
}
?>
view
<?php
session_start();
if (!isset($_SESSION['login'])){
echo"<center><a href='login.php'>silahkan login terlebih dahulu</a></center>";}
else{
if (empty($_SESSION['data_mhs'])){
echo"<center>tidak ada data tersimpan<br/><a href='input.php'>tambahkan data</a></center>";}
else{
?>
<center>
selamat datang, <?php echo $_SESSION['login']; ?><br/>
<a href='input.php'>Input data | <a href='view.php'>lihat data | <a href='logout.php'>logout</a>
</center>
<table border='1' align='center'>
<tr>
<td>No</td>
<td>Npm</td>
<td>Nama</td>
<td>Kelas</td>
<td>Pilihan</td>
</tr>
<?php
$no=0;
foreach($_SESSION['data_mhs'] as $line => $data){
$no++;
$npm=$_SESSION['data_mhs'][$line]['npm'];
$nama=$_SESSION['data_mhs'][$line]['nama'];
$kelas=$_SESSION['data_mhs'][$line]['kelas'];
echo "
<tr>
<td>$no</td>
<td>$npm</td>
<td>$nama</td>
<td>$kelas</td>
<td><a href='delete.php?line=$line'>hapus</a></td>
</tr>";
}
}
}
?>
</table>
No comments:
Post a Comment