Coding Basis Data
Coding Basis Data
php
<?php
$user_name="root";
$password="";
$database="pemerintah";
$host_name="localhost";
$koneksi=mysqli_connect($host_name,$user_name,$password,$database);
if(!$koneksi)
{
die('gagal koneksi:' .mysqli_error());
}
echo"koneksi terbuka";
mysqli_close($koneksi);
?>
2.form_presiden.html
<!DOCTYPE html>
<html>
<head>
<title>Form untuk database</title>
</head>
<body>
<br></br>
<form action="input.php" method="post">
<h3 align="left">DATA PRESIDEN</h3>
<b>Id Presiden =</b> <input type="text" name="id_p"><p></p>
<b>Nama Presiden =</b> <input type="text" name="nama_p"><p></p>
<b>Masa Jabatan =</b> <input type="text" name="masa_j"><p></p>
<b>Email =</b> <input type="text" name="email"><p></p>
<b>NO HP =</b> <input type="text" name="no_hp"><p></p>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Simpan">
<input type="reset" name="Hapus" value="Hapus">
</td>
</tr>
</form>
<a href="menampilkan_data.php">Lihat Data</a>
</body>
</html>
input.php
<?php
$user_name="root";
$password="";
$database="pemerintah";
$host_name="localhost";
$koneksi=mysqli_connect($host_name,$user_name,$password,$database);
if(!$koneksi){
die ('belom konek mas bro' .mysqli_error());
}
//bacavariabel
$imk=$_POST['id_p'];
$nmk=$_POST['nama_p'];
$hmk=$_POST['masa_j'];
$amk=$_POST['email'];
$emk=$_POST['no_hp'];
$data=$imk."".$nmk."".$hmk."".$amk."".$emk."";
//eksekusi query
if(mysqli_query($koneksi,$sql)===TRUE){
echo "data $nmk telah berhasil di input\n";
}
echo"Koneksi terbuka";
mysqli_close ($koneksi);
?>
4.menampilkan_data.php
<?php
print("<tr><td>$n</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</
td><td>$row[4]</td></tr>");
}
print("</table>");
mysqli_close($koneksi);
?>