السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Bagaimana cara menginputkan data dari form ke database mysql di phpmyadmin? berikut caranya:
1. Pastikan laptop anda sudah terinstal dengan
XAMPP, kemudian aktifkan A
pache dan
MySQL.
2. Masuk ke url
"localhost/phpmyadmin".
3.Buat sebuah database baru
"viscabarkah" (nama database bebas).
4. Buatlah sebuah tabel baru
"tbl_beranda" (nama tabel bebas).
5. Masukkan data baru ke
"tbl_beranda".
6. Klik Structure untuk melihat data tabel yang dibuat tadi.
7. Setelah sampai tahap ini, buka direktori tempat anda menginstall xampp tadi, misal :
D://xampp/htdocs/ kemudian buat folder baru
"inputberanda" (nama folder bebas).
Jangan lupa karena kita akan menginput file foto, pastikan foto yang akan ditampilkan harus dalam folder tersebut.
8. Buka aplikasi Notepad C++ (
recomended) dan buat sebuah file
.php dengan file-file yang dibutuhkan sebagai berikut:
-koneksi.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("viscabarkah");
?>
-beranda.php
<html>
<head>
<title>INPUT BERANDA</title>>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<body>
<center>
<div class="table">
<br><br><br><br><br><br>
<h3>Beranda</h3>
<br><br><br>
<form name="" action="proses_beranda.php" method="post">
<table border="0" width="300">
<tr><td>Foto Web</td>
<td>:</td>
<td><input type="file" class="foto_web" name="foto_web" value="" size="65"/>
</td>
</tr>
<tr><td>Deskripsi Web</td>
<td>:</td>
<td><textarea type="text" class="deskripsi_web" name="deskripsi_web" value=""/></textarea>
<tr><td colspan="5">
<center><br><br>
<input type="submit" value="Simpan" name="submit">
<input type="reset" value="Reset" name="reset">
</center>
</td>
</tr>
</table>
</form>
</center>
</div>
</body>
</html>
-style.css
/*----------(#Tabel Beranda)-----------*/
body {
font-family: Calibri;
color: #000;
}
.table h3 {
color: #fff;
font-size: 20px;
width: 125px;
height: 5%;
border-radius: 20px;
padding-top: 7px;
margin-top: -30px;
background-color: #519cd6;
}
.table {
border-radius: 5px;
padding: 5px;
margin-top: 5px;
}
.table tr {
height: 30px;
font-size: 15px;
}
.table input.foto_web {
border: 1px solid #adb2b6;
border-radius: 3px;
height: 35px;
padding: 6px;
margin-bottom: 8px;
margin-left: 25px;
margin-right: 25px;
}
.table textarea.deskripsi_web {
border: 1px solid #adb2b6;
border-radius: 3px;
width: 500px;
height: 150px;
padding: 8px;
margin-bottom: 8px;
margin-left: 25px;
margin-right: 25px;
}
/*----------(#Success Page)-----------*/
.success h3{
color: #fff;
font-size: 20px;
width: 15%;
height: 6%;
border-radius: 20px;
padding-top: 10px;
margin-top: -30px;
margin-bottom: 50px;
background-color: #519cd6;
}
.success h4 {
font-family: Agency FB;
font-size: 30px;
color: #000;
}
.success p {
font-family: Calibri;
font-size: 15px;
width: 10%;
height: 4%;
padding-top: 5px;
border-radius: 20px;
margin-top: 50px;
background-color: #1efd62;
}
-proses_beranda.php
<?php
//panggil file koneksi.php untuk menghubung ke server
include("koneksi.php");
//tangkap data dari form
$foto_web = $_POST['foto_web'];
$deskripsi_web = $_POST['deskripsi_web'];
//simpan data ke database
$query = mysql_query("insert into tbl_beranda values('$foto_web','$deskripsi_web')") or die(mysql_error());
if ($query) {
header("location:success.php");
}
?>
-success.php
<html>
<head>
<title>SUCCESS INPUT</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<!-- Content -->
<center>
<div class="success">
<br><br><br><br><br><br>
<h3>Attention</h3>
<br><br><br>
<h4> ANDA BERHASIL MENGINPUTKAN DATA BARU KE DATABASE !!!</h4>
<br><br>
<br><br>
<br><br>
</div>
</center>
</body>
</html>
-tampil_beranda.php
<html>
<head>
<title>INPUT BERANDA</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<body>
<center>
<!-- Content -->
<center>
<p><i>
<?php
include "koneksi.php";
$sql = "select * FROM tbl_beranda";
$tampil = mysql_query($sql);
while ($data = mysql_fetch_array($tampil)){
echo "<img src='".$data['foto_web']."' width='500px' height='400px'/><br><br>";
echo $data['deskripsi_web']."<br>";
}
?>
</p></i>
</center>
</center>
</html>
8. Selanjutnya, buka web browser kalian (mozilla, chorme dsb) dan ketikan
"localhost/inputberanda/beranda.php" pada address barnya.
9. Isi form beranda tersebut seperti contoh dibawah ini:
10. Dan jika berhasil akan muncul halaman
"success.php"
11. Untuk membuktikan apakah data yang kita buat sudah terinput atau belum, buka
"localhost/phpmyadmin → viscabarkah →
tbl_beranda, jika berhasil akan muncul database yang kita inputkan td kedalam tbl_beranda.
12. Untuk melihat hasil tampilan database yang diinputkan tadi ketik
"localhost/inputberanda/tampil_beranda.php, jika berhasil akan muncul tampilan seperti dibawah ini:
13. Selesai
-Selamat Mencoba-
0 komentar:
Posting Komentar