Tugas Web FrameWork 1

<?php
$koneksi = mysql_connect(“localhost”,”root”,””);
mysql_select_db(“mahasiswa”,$koneksi);
if(!$koneksi){
die (“tidak terkoneksi”);
}
?>

<form name=”formMahasiswa” method=”post” >
<?php
echo ” NIM  : <input type=’text’ size = ‘8’ name = ‘Nim’><br>
Nama : <input type=’text’ name = ‘Nama’><br>
Tanggal Lahir (yyyy/mm/dd): <input type=’text’ name = ‘TL’><br>
Jenis Kelamin : <select name = ‘Jenkel’>
<option value = ‘pria’ selected=”>Pria</option>
<option value = ‘wanita’>Wanita</option>
</select> <br>
Angkatan : <input type=’text’ name = ‘Angkatan’><br>
Alamat : <textarea name = ‘Alamat’ cols=’30’ rows=’4′></textarea><br>
<input type=’submit’ name=’simpan’ value=’submit’></form>” ;

if ($_POST[‘simpan’]==”submit”){
$nim=$_POST[‘Nim’];
$Nama=$_POST[‘Nama’];
$TL=$_POST[‘TL’];
$Jenkel=$_POST[‘Jenkel’];
$Angkatan=$_POST[‘Angkatan’];
$Alamat=$_POST[‘Alamat’];

$sql=”insert into mhs values(‘$nim’,’$Nama’,’$TL’,’$Jenkel’,’$Angkatan’,’$Alamat’)”;
$hasil=mysql_query($sql,$koneksi);
if(!$hasil){echo “Data gagal dimasukan”;}
}
?>

<br>
<hr width=100%>
<?php
$cari=’select *from mhs order by Nim’;
$sql2=mysql_query($cari,$koneksi);
$no=0;
echo “<table>”;
echo “<tr>
<td>No</td><td>Nim</td><td>Nama</td><td>Tanggal Lahir</td><td>Jenkel</td><td>Angkatan</td><td>Alamat</td>
</tr>
“;
while($baris=mysql_fetch_row($sql2)){
$no++;
echo “<tr>
<td>NO</td>
<td>$baris[0]</td>
<td>$baris[1]</td>
<td>$baris[2]</td>
<td>$baris[3]</td>
<td>$baris[4]</td>
<td>$baris[5]</td>
</tr>”;
}
echo “</table>”;
?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s