Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13512088 - Final #118

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions add_comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

include("mysql.php");
$post_id = $_GET['post_id'];
$Nama = $_GET['name'];
$Email = $_GET['email'];
$Tanggal = date("d M Y H:i");
$Komentar = $_GET['content'];

mysql_query("
INSERT INTO comment(post_id,name,email,date,content)
values('$id_post','$Nama','$Email','$Tanggal','$Komentar')
") or die("Comment input failed.");
?>
1 change: 1 addition & 0 deletions assets/js/alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// JavaScript source code
76 changes: 76 additions & 0 deletions blog.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
-- phpMyAdmin SQL Dump
-- version 4.1.12
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 15, 2014 at 05:47 AM
-- Server version: 5.5.40
-- PHP Version: 5.3.28

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `blog`
--

-- --------------------------------------------------------

--
-- Table structure for table `comment`
--

CREATE TABLE IF NOT EXISTS `comment` (
`id` int(3) NOT NULL AUTO_INCREMENT,
`post_id` int(3) NOT NULL,
`date` datetime NOT NULL,
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`content` text NOT NULL,
PRIMARY KEY (`id`),
KEY `post_id` (`post_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `post`
--

CREATE TABLE IF NOT EXISTS `post` (
`id` int(3) NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`content` text NOT NULL,
`date` datetime NOT NULL,
`num_comment` int(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

--
-- Dumping data for table `post`
--

INSERT INTO `post` (`id`, `title`, `content`, `date`, `num_comment`) VALUES
(2, 'sdfghjk', 'dfghjkl', '2014-10-14 17:00:00', NULL),
(3, 'sdfghjk', 'dhkdfgkdfgkdgdfkgf', '2014-10-14 17:00:00', NULL),
(4, 'sdfghjk', 'sdfghjvbnghju', '2014-10-14 17:00:00', NULL),
(5, 'sdfghjk', 'sdfghjvbnghju', '2014-10-14 17:00:00', NULL),
(6, 'sdfghjk', 'sdfghjvbnghju', '2014-10-14 17:00:00', NULL),
(7, 'rrr', 'vbnmfffkfkf', '2013-07-04 12:00:00', NULL),
(8, 'rrr', 'vbnmfffkfkf', '2013-07-04 12:00:00', NULL),
(9, 'gfggdf', 'wfghjhgfdsddhgtr', '2014-10-14 17:00:00', NULL),
(10, 'vvv', 'fgkdfg.dgd', '2013-07-04 12:00:00', NULL),
(11, 'fgdfg', 'kfjlfjlsdf', '2014-10-14 17:00:00', NULL),
(12, 'fgdfg', 'kfjlfjlsdf', '2014-10-14 17:00:00', NULL),
(13, 'fgdfg', 'kfjlfjlsdf', '2014-10-14 17:00:00', NULL),
(15, 'dfkfkfkgkf', 'sfjdjfjdfjd', '2016-04-03 11:34:36', NULL);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
111 changes: 111 additions & 0 deletions edit_post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="Deskripsi Blog">
<meta name="author" content="Judul Blog">

<!-- Twitter Card -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="omfgitsasalmon">
<meta name="twitter:title" content="Simple Blog">
<meta name="twitter:description" content="Deskripsi Blog">
<meta name="twitter:creator" content="Simple Blog">
<meta name="twitter:image:src" content="{{! TODO: ADD GRAVATAR URL HERE }}">

<meta property="og:type" content="article">
<meta property="og:title" content="Simple Blog">
<meta property="og:description" content="Deskripsi Blog">
<meta property="og:image" content="{{! TODO: ADD GRAVATAR URL HERE }}">
<meta property="og:site_name" content="Simple Blog">

<link rel="stylesheet" type="text/css" href="assets/css/screen.css" />
<link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico">

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<title>Simple Blog | Edit Post</title>

</head>

<body class="default">
<div class="wrapper">

<nav class="nav">
<a style="border:none;" id="logo" href="index.php"><h1>Simple<span>-</span>Blog</h1></a>
</nav>

<article class="art simple post">


<h2 class="art-title" style="margin-bottom:40px">-</h2>

<div class="art-body">
<div class="art-body-inner">
<h2>Edit Post</h2>

<?php
include ("mysql.php");
if (!empty($_POST))
{
mysql_safe_query("UPDATE post SET title = '".$_POST['Title'] ."' ,body = '".$_POST['Content'] ."' ,date = '".$_POST['Date'] ."' WHERE id = ".$_GET['id']);
$title = $_POST['Title'];
$date = $_POST['Date'];
$content = $_POST['Content'];
echo ('<script type="text/javascript"> alert("Edit post successful.");</script>');
}
else
{
$result = mysql_safe_query("SELECT * FROM post WHERE id = ".$_GET['id']);
$data = mysql_fetch_row($result);
}
?>

<div id="contact-area">
<form method="post">
<label for="Judul">Title:</label>
<input type="text" name="Title" id="Title" value = "<?php echo mysql_fetch_row($result) ?>">

<label for="Tanggal">Date:</label>
<input type="text" name="Date" id="Date" value = "<?php echo $row['date'] ?>" placeholder ="yyyy-mm-dd hh:mm:ss">

<label for="Konten">Content:</label><br>
<textarea name="Content" rows="20" cols="20" id="Content" ><?php echo $row['content'] ?></textarea>

<input type="submit" name="submit" value="Edit" class="submit-button">
</form>
</div>

</div>
</div>

</article>

<footer class="footer">
<div class="back-to-top"><a href="">Back to top</a></div>
<!-- <div class="footer-nav"><p></p></div> -->
<div class="psi">&Psi;</div>
<aside class="offsite-links">
Asisten IF3110 /
<a class="rss-link" href="#rss">RSS</a> /
<br>
<a class="twitter-link" href="http://twitter.com/YoGiiSinaga">Yogi</a> /
<a class="twitter-link" href="http://twitter.com/sonnylazuardi">Sonny</a> /
<a class="twitter-link" href="http://twitter.com/fathanpranaya">Fathan</a> /
<br>
<a class="twitter-link" href="#">Renusa</a> /
<a class="twitter-link" href="#">Kelvin</a> /
<a class="twitter-link" href="#">Yanuar</a> /

</aside>
</footer>

</div>

</body>
</html>
116 changes: 116 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="Deskripsi Blog">
<meta name="author" content="Judul Blog">

<!-- Twitter Card -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="omfgitsasalmon">
<meta name="twitter:title" content="Simple Blog">
<meta name="twitter:description" content="Deskripsi Blog">
<meta name="twitter:creator" content="Simple Blog">
<meta name="twitter:image:src" content="{{! TODO: ADD GRAVATAR URL HERE }}">

<meta property="og:type" content="article">
<meta property="og:title" content="Simple Blog">
<meta property="og:description" content="Deskripsi Blog">
<meta property="og:image" content="{{! TODO: ADD GRAVATAR URL HERE }}">
<meta property="og:site_name" content="Simple Blog">

<link rel="stylesheet" type="text/css" href="assets/css/screen.css" />
<link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico">

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<title>Simple Blog</title>


</head>

<body class="default">
<div class="wrapper">

<nav class="nav">
<a style="border:none;" id="logo" href="index.php"><h1>Simple<span>-</span>Blog</h1></a>
<ul class="nav-primary">
<li><a href="new_post.php">+ Tambah Post</a></li>
</ul>
</nav>

<div id="home">

<?php
include 'mysql.php';

$result = mysql_safe_query('SELECT * FROM post ORDER BY date DESC');

if(!mysql_num_rows($result)) {
echo 'No posts yet.';
} else {
while($row = mysql_fetch_assoc($result)) {
echo '<div class="posts">
<nav class="art-list">
<ul class="art-list-body">
<li class="art-list-item">
<div class="art-list-item-title-and-time">
<h2 class="art-list-title"><a href="post.php?id='.$row['id'].'">'.$row['title'].'</a></h2>
<div class="art-list-time">'.$row['date'].'</div>
<div class="art-list-time"><span style="color:#F40034;">&#10029;</span> Featured</div>
</div>
<p>'.$row['content'].'</p>
<p>
<a href="edit_post.php?id='.$row['id'].'">Edit</a> | <a href="javascript:void(0);" onclick ="delPost('.$row['id'].');">Hapus</a>
</p>
</li>
</ul>
</nav>';
}
}
if (isset($_GET['delete']))
{
mysql_safe_query("DELETE FROM post WHERE id = $_GET[delete]");
}
$result = mysql_safe_query('SELECT * FROM post');
?>

<footer class="footer">
<div class="back-to-top"><a href="">Back to top</a></div>
<!-- <div class="footer-nav"><p></p></div> -->
<div class="psi">&Psi;</div>
<aside class="offsite-links">
Asisten IF3110 /
<a class="rss-link" href="#rss">RSS</a> /
<br>
<a class="twitter-link" href="http://twitter.com/YoGiiSinaga">Yogi</a> /
<a class="twitter-link" href="http://twitter.com/sonnylazuardi">Sonny</a> /
<a class="twitter-link" href="http://twitter.com/fathanpranaya">Fathan</a> /
<br>
<a class="twitter-link" href="#">Renusa</a> /
<a class="twitter-link" href="#">Kelvin</a> /
<a class="twitter-link" href="#">Yanuar</a> /

</aside>
</footer>

</div>

<script>
function delPost(delID)
{
var confDialog = confirm("Delete this post?");
if (confDialog)
{
window.location = 'index.php?delete=' + delID;
}
}
</script>

</body>
</html>
25 changes: 25 additions & 0 deletions load_comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
include("mysql.php");
$id_post = $_GET['id'];
$query_komentar = mysql_query("
SELECT *
FROM comment
WHERE post_id = '$post_id'
ORDER BY id DESC
") or die("No comments to show.");

while($row = mysql_fetch_object($query_komentar)){
$post_id = $row['post_id'];
$name = $row['name'];
$email = $row['email'];
$date = $row['date'];
$content = $row['content'];
echo "<li class=\"art-list-item\">";
echo "<div class=\"art-list-item-title-and-time\">";
echo "<h2 class=\"art-list-title\"><a href=\"mailto:$email\">$name</a></h2>";
echo "<div class=\"art-list-time\">$date</div>";
echo "</div>";
echo "<p>$content</p>";
echo "</li>";
}
?>
22 changes: 22 additions & 0 deletions mysql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// mysql.php
function mysql_safe_string($value) {
$value = trim($value);
if(empty($value)) return 'NULL';
elseif(is_numeric($value)) return $value;
else return "'".mysql_real_escape_string($value)."'";
}

function mysql_safe_query($query) {
$args = array_slice(func_get_args(),1);
$args = array_map('mysql_safe_string',$args);
return mysql_query(vsprintf($query,$args));
}

function redirect($uri) {
header('location:'.$uri);
exit;
}

mysql_connect('localhost','root','root');
mysql_select_db('blog');
Loading