Ekspresi | Belajar HTML dan PHP | Sunda | Kontak | Gmail | Uang Adsense
Kemahasiswaan Kilas Santai
PMB Online STMIK Jabar 2021
STMIK JABAR
LP3I Tasikmalaya
STAI Al-Falah
Pengobatan Ruqyah
Belajar Pemrograman PHP, MySQL, Framework CI, Domain, Hosting, CMS Wordpress, Framework Laravel. Yang Penting ada menu DAFTAR ISI
Inkubator | Daftar Isi | Bisnis Bitcoin | Tools Penting | PrivacyPolicy | Inggris Arab

Wednesday, January 8, 2014

Cara Membuat Fasilitas Kontak Dengan PHP


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%">&nbsp;</td>
              <td width="75%">&nbsp;</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>&nbsp;</td>
              <td><?php echo $tls_pesan?></td>
            </tr>
            <tr>
              <td>&nbsp;</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

"Bitcoin and Forex are high risk business. We must join them smartly."
Belajar Bahasa Inggris dan Arab di Telegram dan FB Gratis!
Youtube: Katabah Com: Menuju 1 jt Konten :)

No comments:

Post a Comment