Posted by : I Made Juniawan Selasa, 18 Juni 2013


Import data excel ke mysql

Pertama buat dulu form nya:

<!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=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="komentar/style.css" />
<title>juniawa89.blogspot.com</title>
</head>
<body>

<style>
#comment {
margin:20px 0 0 20px;
border: 2px solid #848484;
border-radius:20px;
-moz-border-radius:20px;
max-height: 90%;
font-weight: bold;
color: #606060;
padding: 10px;
width: 90%;
background-color: #dcdcdc;
}
#publishcomment {
border: 2px solid #848484;
box-shadow: 12px 12px 7px #888888;
margin: 30px 0 50px 20px;
padding: 10px;
max-height: 100%;
color: #3d3d3d;
width: 90%;
font-size: 12px;
line-height: 15px;
}
#publishcomment hr {
color: #ccc;
}
#publishcomment a {
color: #da5700;
text-decoration: none;
font-weight:normal;
}
#publishcomment a:link {
font-weight: bold;
}
#publishcomment a:hover {
text-decoration: underline;
}
</style>

<div id="comment">
<p><b><font size="+2">Leave a Comment</font></b></p><br />
<p>Apabila anda memiliki pertanyaan yang membutuhkan jawaban secepatnya, anda bisa langsung menghubungi kami di juniawan89.blogspot.com</p><br />
<form name="submitcomment" method="post" action="komentar/submitcomment.php">Nama:<br>
<input name="nama" type="text" size="40">
<br>
Email(optional):<br><input name="email" type="text" size="40">
<br>
Website(optional):<br><input name="website" type="text" size="40">
<br>
Komentar:<br><textarea name="komentar" rows="6" cols="50"></textarea><br>
<input name="art_id" value="1" type="hidden">
<input name="art_url" value="<?php echo $_SERVER['PHP_SELF']; ?>" type="hidden"><br>
<input name="tombol" value="Kirim" type="submit"></form></div>
<div id="publishcomment">
<?php include("komentar/publishcomment.php"); getcomment("1"); ?></div>

</body>
</html>


Kedua buat file untuk publish komentar :

<?php
$con=mysql_connect("localhost", "root", "");
if(!$con)
die("Tidak dapat melakukan koneksi ke server MySQL");
mysql_select_db("database", $con);
?>
<?php
function getcomment($art_id){
$commentquery = mysql_query("SELECT * FROM tabel WHERE cout=1 and art_id='$art_id'  
ORDER BY id DESC") or die(mysql_error());
$commentNum = mysql_num_rows($commentquery);
echo "<h4>" . "Current comment(s)..." . "</h4>";
echo "<b>" . $commentNum . " comment(s) so far. Leave a comment..." .
"</b>" . "<br />" . "<br />";
echo "<hr>";
while($row = mysql_fetch_array($commentquery))
 {
 echo "<img src=\"komentar/$row[gmb]\" width=\"40px\" height=\"40px\" align=\"right\"><br />";
 echo "<b>" . $row['nama'] . "</b>" . " " . " | " . " " . "<i>" .
$row['date'] . "</i>" . "<br />" . "<br />" . $row['komentar'] . "<br />";
 echo "<hr>";
 }
}
?>

Ketiga buat file untuk submit komentar :


<?php
if($_POST["tombol"]=="Kirim")
{
$nama=$_POST["nama"];
$email=$_POST["email"];
$website=$_POST["website"];
$komentar=$_POST["komentar"];
$art_id=$_POST["art_id"];
$art_url=$_POST["art_url"];

if(empty($nama)){
$_POST["nama"]='anonymous';
$user='user0.png';
}else{
$user='user1.png';
}
if(empty($komentar)){
echo "<meta http-equiv='refresh' content='2; url=$art_url'>";
echo "<script>
function kembali(){
alert(\"Pesan masih kosong, isi dahulu..!!\");
}
kembali();
</script>";
exit;}
}

//connect database
$con=mysql_connect("localhost", "root", "");
if(!$con)
die("Tidak dapat melakukan koneksi ke server MySQL");

//Menampilkan data
mysql_select_db("hero", $con);

$sql="INSERT INTO comment (nama, email, website, komentar, art_id, art_url,
date, gmb)
VALUES
('$_POST[nama]','$_POST[email]','$_POST[website]', '$_POST[komentar]',
'$_POST[art_id]', '$_POST[art_url]', NOW(), '$user')";

if (!mysql_query($sql,$con))
 {
 die('Error: ' . mysql_error());
 }
echo "<meta http-equiv='refresh' content='0; url=$art_url'>";
echo "<script>
function kembali(){
alert(\"Terimakasih atas komentar anda.. Komentar akan muncul setelah di approve oleh admin.\");
}
kembali();
</script>";
exit; 


//Memutuskan koneksi
mysql_close($con);
?>

Download code lengkap disini

Selesai...
Semoga Bermanfaat....











2 Responses so far.

Leave a Reply

Pengunjung yang baik selalu memberikan masukan / komentar....

Subscribe to Posts | Subscribe to Comments

Popular Post

Lihat

Cari

Total Tayangan

Follow by Email

What is this ???

Share It

Recent Posts

Google pagerank and Worth
Diberdayakan oleh Blogger.

- Copyright © Juniawan89.blogspot.com -