Kontak kontak seringkali dijumpai pada website atau blog. Dalam implementasinya dapat dikoneksikan dengan e-mail seperti Gmail. Namun untuk kesempatan ini pesan pada menu kontak terkirim ke database MySQL di localhost.
1.
Software:
·
WampServer 2.2
·
Apache 2.2.21
·
PHP 5.3.10
·
MySQL 5.5.20
2.
Buat database: ikhbaar
3.
Buat tabel: kontak
Column
|
Type
|
Length
|
Extra
|
id
|
Integer
|
5
|
Auto_Increment
|
tanggal
|
Varchar
|
20
|
|
password
|
Varchar
|
16
|
|
username
|
Varchar
|
16
|
|
tentang
|
Varchar
|
30
|
|
pesan
|
Text
|
|
|
4.
Buat file: 3kontak_proses.php
Ketik script berikut:
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "ikhbaar";
$conn_db = mysql_connect($db_host, $db_user,
$db_password) or die("settingan database server salah");
$select_db = mysql_select_db($db_name) or
die("Database tidak diketemukan");
$password = $_POST["password"];
$username = $_POST["username"];
$tentang = $_POST["tentang"];
$pesan = $_POST["pesan"];
$tanggal = date("d M Y");
if (!$password || !$username || !$tentang ||
!$tanggal)
{
header("location:
3kontak_tampil.php?id_massage=1");
exit;
}
else
if (!$pesan)
{
header("location:
3kontak_tampil.php?id_massage=4");
exit;
}
$query = "INSERT INTO kontak (tanggal,
password, username, tentang, pesan)
VALUES ('$tanggal', '$password', '$username',
'$tentang', '$pesan')";
$result = mysql_query($query);
mysql_close($conn_db);
if ($result)
{
header("location:
3kontak_tampil.php?id_massage=2");
exit;
}
else
{
header("location:
3kontak_tampil.php?id_massage=3");
exit;
}
//Sumber: Abdul Hanan. Belajar PHP. Nama file:
belajar_php.pdf
?>
5.
Buat
file: 3kontak_tampil.php
Ketik script berikut:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Kontak</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<?php
$id_massage =
isset($_GET["id_massage"]) ? $_GET["id_massage"] :
"";
switch($id_massage)
{
case
1:
$tls_pesan
= "Isikan seluruh data dengan benar";
break;
case
2:
$tls_pesan
= "Data Berhasil Dimasukkan";
break;
case
3:
$tls_pesan
= "Data Gagal dimasukkan";
break;
case
4:
$tls_pesan
= "Pesan belum diisi";
break;
default:
$tls_pesan
= "";
break;
}
?>
<body>
<table width="324"
border="1" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="320"><table width="100"
border="1" cellspacing="0" cellpadding="0">
<tr>
<td>KONTAK</td>
</tr>
<tr>
<td><form action="3kontak_proses.php" method="post"
name="guest book" id="guest book">
<table width="85%"
border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="25%"> </td>
<td width="75%"> </td>
</tr>
<tr>
<td>Username:</td>
<td><input name="username" type="text"
id="username" size="25"
maxlength="16"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password"
id="password" size="25"
maxlength="16"></td>
</tr>
<tr>
<td>Tentang:</td>
<td><input name="tentang" type="text"
id="tentang" size="25"
maxlength="16"></td>
</tr>
<tr>
<td>Pesan:</td>
<td><textarea name="pesan" cols="35"
rows="7" id="pesan"></textarea></td>
</tr>
<tr>
<td> </td>
<td><?php echo $tls_pesan?></td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit"
id="submit" value="Kirim">
<input name="reset" type="reset"
id="reset" value="Batal"></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td align="center"><span
class="style2"></span></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<?php
//Sumber: Abdul Hanan. Belajar PHP. Nama file:
belajar_php.pdf
?>
6.
Hasilnya:
***
Sumber: Abdul Hanan. Belajar PHP. Nama file: belajar_php.pdf
"Boleh Konsultasi Masuk Jurusan Sistem Informasi via IG atau Tiktok."
|
Tips Skripsi Program Studi Sistem Informasi |
|
No comments:
Post a Comment