nanti terdiri dari beberapa file:
- index.php
- inc.connectdb.php
- addnews.php
- newsim.php
pertama-tama buat database:
Spoiler for database:
Code:
-- phpMyAdmin SQL Dump -- version 3.2.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Oct 22, 2010 at 09:27 PM -- Server version: 5.1.37 -- PHP Version: 5.2.12 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `infernobay` -- -- -------------------------------------------------------- -- -- Table structure for table `news` -- CREATE TABLE IF NOT EXISTS `news` ( `id` int(5) NOT NULL AUTO_INCREMENT, `News` text CHARACTER SET ascii NOT NULL, `Title` varchar(80) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `date` date NOT NULL, `time` time NOT NULL, `Headline` text NOT NULL, PRIMARY KEY (`id`), FULLTEXT KEY `news` (`News`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;
inc.connectdb.php :
Spoiler for inc.connectdb.php:
PHP Code:
<?php
$my['host'] = "localhost"; $my['user'] = "root"; $my['pass'] = ""; $my['db'] = "infernobay";$connect = mysql_connect($my['host'], $my['user'], $my['pass']);
if(! $connect) {
echo("Sorry, But We Can't Connect to the database");
mysql_error();
} mysql_select_db($my['db'])
or die ("The Database Doesn't Exists".mysql_error()); ?>
habis itu buat index.php :
Spoiler for index.php:
PHP Code:
<?php include "inc.connectdb.php";$sql="SELECT * FROM news ORDER BY id DESC LIMIT 10 "; $result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){; ?>
<table width="500">
<tr>
<td><hr></td>
</tr>
<tr>
<td> <font face="Calibri"><?php echo ($rows['Title']); ?></font>
</td>
</tr>
<tr>
<td bordercolor="#0033FF"><font size="2"><?php echo ($rows['News'] ) ;?></font></td>
</tr>
<tr>
<td><font size="1">Posted at : <?php echo ($rows['date'] ) ;
echo " ";
echo ($rows['time']);?></font></td>
</tr>
<tr>
<td></td>
<td></td></tr>
</table>
<?php } ?> <a href="addnews.php>Buat Berita</a>
Spoiler for ket ::
PHP Code:
$sql="SELECT * FROM news ORDER BY id DESC LIMIT 10 ";
PHP Code:
ORDER BY id DESC LIMIT 10
PHP Code:
while($rows=mysql_fetch_array($result)){;
PHP Code:
<?php echo ($rows['Title']); ?>
PHP Code:
Posted at : <?php echo ($rows['date'] ) ;
echo " ";
echo ($rows['time']);?>
sekarang addnews.php :
Spoiler for addnews.php:
PHP Code:
<form action="newsim.php" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="18%"><font face="Calibri">JUDUL</font></td>
<td width="2%">:</td>
<td width="80%"><input name="judul" type="text" id="judul"></td>
</tr>
<tr>
<td><font face="Calibri">HEADLINE</font></td>
<td>:</td>
<td><textarea cols="50" id="textNews" name="headline" rows="10"></textarea></td>
</tr>
<tr>
<td><font face="Calibri">NEWS</font></td>
<td>:</td>
<td><textarea cols="80" id="textNews" name="berita" rows="10"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
kalo udah sekarang newsim.php :
Spoiler for newsim.php:
PHP Code:
<?php include "inc.connectdb.php"; //Untuk mengantisipasi terjadinya error error_reporting('E_NONE');
$post = $_POST['judul']; $news = $_POST['berita']; $head = $_POST['headline']; $date=date("Y-m-d"); $time=date("H:i"); //Apabila judul Kosong if ($post == "") {
echo "Tolong Di isi</br>";
} //Apabila Berita Kosong elseif ($news == "") {
echo "Tolong isi Berita";
}
else { $order="INSERT INTO news(News,Title,Headline,date,time) VALUES('$news','$post','$head','$date','$time')"; $result=mysql_query($order) or die ('Error: ' .mysql_error());
if ($result)
{
echo "Saved </br>";
}
else
{
echo "Gagal";
}
} ?>
Spoiler for ket ::
PHP Code:
$post = $_POST['judul']; $news = $_POST['berita']; $head = $_POST['headline']; $date=date("Y-m-d"); $time=date("H:i");
PHP Code:
if ($post == "") {
echo "Tolong Di isi</br>";
} //Apabila Berita Kosong elseif ($news == "") {
echo "Tolong isi Berita";
}
PHP Code:
else { $order="INSERT INTO news(News,Title,Headline,date,time) VALUES('$news','$post','$head','$date','$time')"; $result=mysql_query($order) or die ('Error: ' .mysql_error());
udah dulu y gan
SOURCE