0% found this document useful (0 votes)
47 views5 pages

Formulir Data Mahasiswa PTIK

The document contains code for a web form to input student data into a database. It includes PHP code to connect to a MySQL database, insert new student records, and display existing records in a table. The form allows entering a student's name, gender, birthplace, date of birth, address, phone number and submitting or resetting the form. On submit, it checks if the student ID already exists before inserting the new data into the database table. It then displays all student records from the table.

Uploaded by

Novia Herlina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views5 pages

Formulir Data Mahasiswa PTIK

The document contains code for a web form to input student data into a database. It includes PHP code to connect to a MySQL database, insert new student records, and display existing records in a table. The form allows entering a student's name, gender, birthplace, date of birth, address, phone number and submitting or resetting the form. On submit, it checks if the student ID already exists before inserting the new data into the database table. It then displays all student records from the table.

Uploaded by

Novia Herlina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

NOVIA HERLINA

2517130
PTIK – 6D
WEB PROGRAMING
1. mhs.php
<!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>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<p align="center"><strong>DATA MAHASISWA</strong></p>
<div align="center">
<table width="340" border="1">
<tr>
<td width="113" height="26" bgcolor="#CCCCCC">NIM</td>
<td width="211" bgcolor="#CCCCCC"><label for="nim2"></label>
<input name="nim" type="text" id="nim2" value="" /></td>
</tr>
<tr>
<td height="27" bgcolor="#CCCCCC">Nama</td>
<td bgcolor="#CCCCCC"><label for="nama"></label>
<input type="text" name="nama" id="nama" /></td>
</tr>
<tr>
<td height="26" bgcolor="#CCCCCC">Gender</td>
<td bgcolor="#CCCCCC"><label for="gender"></label>
<select name="gender" id="gender">
<option>L</option>
<option>P</option>
</select></td>
</tr>
<tr>
<td height="26" bgcolor="#CCCCCC">Tempat Lahir</td>
<td bgcolor="#CCCCCC"><label for="tmp_lahir"></label>
<input type="text" name="tmp_lahir" id="tmp_lahir" /></td>
</tr>
<tr>
<td height="28" bgcolor="#CCCCCC">Tanggal Lahir</td>
<td bgcolor="#CCCCCC"><label for="tgl"></label>
<input type="text" name="tgl" id="tgl" /></td>
</tr>
<tr>
<td height="36" bgcolor="#CCCCCC">Alamat</td>
<td bgcolor="#CCCCCC"><label for="alamat"></label>
<textarea name="alamat" id="alamat"></textarea></td>
</tr>
<tr>
<td height="26" bgcolor="#CCCCCC">Telp/Hp</td>
<td bgcolor="#CCCCCC"><label for="hp"></label>
<input type="text" name="hp" id="hp" /></td>
</tr>
<tr>
<td height="45" colspan="2" bgcolor="#666666"><div align="center">
<input type="submit" name="simpan" id="simpan" value="SIMPAN" />
<input type="reset" name="batal" id="batal" value="BATAL" />
</div></td>
</tr>
</table>
<?php
if(isset($_POST['simpan']))
{
include "koneksi.php";
//---variabel yang akan disimpan
$nim=$_POST['nim'];
$nama=$_POST['nama'];
$gender=$_POST['gender'];
$tmp_lahir=$_POST['tmp_lahir'];
$tgl=$_POST['tgl'];
$alamat=$_POST['alamat'];
$hp=$_POST['hp'];
//---cek datanya terlebih dahulu
$koneksi= mysqli_connect('localhost', 'root', '',
'db_akademik');
$cekdata="select * from mhs where nim='$nim'";
$ada=mysqli_query($koneksi,$cekdata) or die
(mysqli_error());
if(mysqli_num_rows($ada)>0)
{
echo "<script> alert('Data Sudah Ada!'); </script>";
}
else
{
$sql="insert into mhs values
('$nim',
'$nama',
'$gender',
'$tmp_lahir',
'$tgl',
'$alamat',
'$hp')";
mysqli_query($koneksi, $sql);
echo "<script> alert('Data Berhasil disimpan.');
</script>";
}

}
?>
<p>&nbsp;</p>
<table width="828" height="79" border="1">
<tr bgcolor="#CCCCCC">
<td width="38" height="42"><div align="center">NO</div></td>
<td width="65"><div align="center">NIM</div></td>
<td width="102"><div align="center">NAMA</div></td>
<td width="62"><div align="center">GENDER</div></td>
<td width="103"><div align="center">TEMPAT LAHIR</div></td>
<td width="76"><div align="center">TGL LAHIR</div></td>
<td width="80"><div align="center">ALAMAT</div></td>
<td width="131"><div align="center">TELP/HP</div></td>
<td colspan="2"><div align="center">ACTION</div></td>
</tr>
<?php
include "koneksi.php";
$koneksi= mysqli_connect('localhost', 'root', '', 'db_akademik');
$sql="select * from mhs";
$hasil=mysqli_query($koneksi,$sql);
$no=1;
while ($data=mysqli_fetch_array($hasil))
{
?>
<tr>
<td><?php echo $no;?></td>
<td><?php echo $data['nim'];?></td>
<td><?php echo $data['nama'];?></td>
<td><?php echo $data['gender'];?></td>
<td><?php echo $data['tmp_lahir'];?></td>
<td><?php echo $data['tgl'];?></td>
<td><?php echo $data['alamat'];?></td>
<td><?php echo $data['hp'];?></td>
<td width="51"><div align="center">Edit</div></td>
<td width="56"><div align="center">Hapus</div></td>
</tr>
<?php
$no++;
}
?>
</table>
<p>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
</body>
</html>

2. koneksi.php
<?php
error_reporting(E_ALL^E_DEPRECATED);
$server="localhost";
$user="root";
$pass="";
$db = "db_akademik";
$koneksi = mysqli_connect($server,$user,$pass) or die ("koneksi gagal");
mysqli_select_db($koneksi, $db) or die ("Databasenya belum aktif");
?>

You might also like