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

Push to IF3110 Simple Blog #117

Open
wants to merge 1 commit 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
30 changes: 30 additions & 0 deletions ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<html>
<head>
<?php
$con=mysqli_connect("localhost","root","","blog_posts");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// escape variables for security
$id = $_POST['id'];
$sql="SELECT * FROM comment WHERE comment_post_id = '$id'";

if (!($result = mysqli_query($con,$sql))) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
$row = mysqli_fetch_array($result);
?>
</head>
<body>
<li class="art-list-item">
<div class="art-list-item-title-and-time">
<h2 class="art-list-title"><a href='' id="ajaxnama"><?php echo $row['comment_name']; ?></a></h2>
<div class="art-list-time" id="ajaxtanggal"><?php echo $row['comment_date']; ?></div>
</div>
<p><div id="ajaxkomentar"><?php echo $row['comment_content']; ?></div></p>
</li>
</body>
</html>
76 changes: 76 additions & 0 deletions blog_posts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
-- phpMyAdmin SQL Dump
-- version 3.5.2.2
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Oct 15, 2014 at 01:19 AM
-- Server version: 5.5.27
-- PHP Version: 5.4.7

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_posts`
--
CREATE DATABASE `blog_posts` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `blog_posts`;

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

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

CREATE TABLE IF NOT EXISTS `comment` (
`comment_post_id` int(11) NOT NULL,
`comment_name` varchar(80) NOT NULL,
`comment_date` varchar(50) NOT NULL,
`comment_content` varchar(600) NOT NULL,
`comment_id` int(11) NOT NULL AUTO_INCREMENT,
`comment_email` varchar(40) NOT NULL,
PRIMARY KEY (`comment_id`),
UNIQUE KEY `comment_post_id` (`comment_post_id`),
UNIQUE KEY `comment_id` (`comment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

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

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

CREATE TABLE IF NOT EXISTS `post` (
`post_content` text NOT NULL,
`post_date` varchar(20) NOT NULL,
`post_title` varchar(200) NOT NULL,
`post_id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`post_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ;

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

INSERT INTO `post` (`post_content`, `post_date`, `post_title`, `post_id`) VALUES
(' Wooooow holllll', '14,10,16,14,14,14', 'Haloo', 29);

--
-- Constraints for dumped tables
--

--
-- Constraints for table `comment`
--
ALTER TABLE `comment`
ADD CONSTRAINT `comment_ibfk_1` FOREIGN KEY (`comment_post_id`) REFERENCES `post` (`post_id`) ON DELETE CASCADE ON UPDATE CASCADE;

/*!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 */;
23 changes: 23 additions & 0 deletions connect_comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
$con=mysqli_connect("localhost","root","","blog_posts");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// escape variables for security
$comment_name = $_POST['Nama'];
$comment_email = $_POST['Email'];
$comment_content = $_POST['Komentar'];
$comment_date = $_POST['tanggal'];
$comment_post_id = $_POST['id'];


$sql="INSERT INTO comment (comment_post_id, comment_name, comment_email, comment_content, comment_date)
VALUES ('$comment_post_id','$comment_name', '$comment_email', '$comment_content', '$comment_date')";

if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
19 changes: 19 additions & 0 deletions connect_post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
header('Location: index.php');
$con=mysqli_connect("localhost","root","","blog_posts");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$post_title = $_POST['Judul'];
$post_date = $_POST['Tanggal'];
$post_content = $_POST['Konten'];
$sql="INSERT INTO post (post_title, post_date, post_content)
VALUES ('$post_title', '$post_date', '$post_content')";

if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
127 changes: 127 additions & 0 deletions edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<!DOCTYPE html>
<html>
<head>
<?php
// Create connection
$con=mysqli_connect("localhost","root","","blog_posts");

// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$id = $_GET['id'];
$sql = "SELECT * FROM post WHERE post_id = '$id'";
$sql1 = "SELECT * FROM comment WHERE comment_post_id = '$id'";
if (!($result = mysqli_query($con,$sql)) || !($result1 = mysqli_query($con,$sql1))) {
die('Error: ' . mysqli_error($con));
}

mysqli_close($con);
?>
<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]-->

<?php $row = mysqli_fetch_array($result) ?>
<title>Simple Blog | Tambah 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>
<ul class="nav-primary">
<li><a href="new_post.php">+ Tambah Post</a></li>
</ul>
</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>

<div id="contact-area">
<?php echo '<form method="post" action="update_post.php?id='.$row['post_id'].'">' ?>
<label for="Judul">Judul:</label>
<?php echo '<input type="text" name="Judul" id="Judul" value='.$row['post_title'].'>' ?>

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

<input type="submit" name="submit" value="Simpan" 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>

<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/fittext.js"></script>
<script type="text/javascript" src="assets/js/app.js"></script>
<script type="text/javascript" src="assets/js/respond.min.js"></script>
<script type="text/javascript">
var ga_ua = '{{! TODO: ADD GOOGLE ANALYTICS UA HERE }}';

(function(g,h,o,s,t,z){g.GoogleAnalyticsObject=s;g[s]||(g[s]=
function(){(g[s].q=g[s].q||[]).push(arguments)});g[s].s=+new Date;
t=h.createElement(o);z=h.getElementsByTagName(o)[0];
t.src='//www.google-analytics.com/analytics.js';
z.parentNode.insertBefore(t,z)}(window,document,'script','ga'));
ga('create',ga_ua);ga('send','pageview');
</script>

</body>
</html>
16 changes: 16 additions & 0 deletions hapus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
header('Location: index.php');
// Create connection
$con=mysqli_connect("localhost","root","","blog_posts");
$id = $_GET['id'];
echo $id;
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "DELETE FROM post WHERE post_id ='$id'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
Loading