Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Example / Listing] A Simple Blog (not a request, an open-source thing)  (Read 2152 times)

0 Members and 1 Guest are viewing this topic.

PoeFacedKilla

Prussian Killer Bee
[Example / Listing] A Simple Blog (not a request...
« on: May 12, 2006, 09:38:40 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Well, I was messing around the other day, and I actually made something that could be turned into something useful.  A blog!!!

First Off, 

Requirements:
PHP
MySQL
CSS Knowledge

An SQL Query:

CREATE TABLE blog_entries (
id INT NOT NULL AUTO_INCREMENT ,
date TEXT NOT NULL ,
author TEXT NOT NULL ,
title VARCHAR (30 )NOT NULL ,
entry LONGTEXT NOT NULL ,
PRIMARY KEY (id)
);

Now with the PHP coding:

Create a your blog directory. And under that directory create another one called admin.

Now go back to the blog directory and create a new file called func.php,

Start off your page:
Code: [Select]
<?php

Now we need four variables:
Host, Username, DB, and Password:
Code: [Select]
$db ='yourdb'
$host ='localhost';
$username ='yoursite_username';
$pass ='yourpass';

(change to fit your DB settings)

now, the code that connects
Code: [Select]
$dbh=mysql_connect ("$host", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$db");

now end your page:
Code: [Select]
?>
Now we're done with the first page, now time to build the ADMIN section.

under admin section

Create a page called index.php

Code: [Select]
<html>
<head>
<title>Your Blog</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h3><a href="post.php" class="adminlink">Post a blog</a></h3><br />
<h3><a href="edit.php" class="adminlink">Edit a blog</a></h3><br />
<h3><a href="delete.php" class="adminlink">Delete a blog</a></h3><br />
</body>
</html>

Now create a page called post.php:

Code: [Select]
<html>
<head>
<title>Post a Blog</title>
</head>
<body>
<form action="postpro.php" method="post">
Title: <input type="text" name="title"><br />
Username: <input type="text" name="user"><br />
Post: <text area style="width: 300px; height:200px" name="text"></textarea><br />
<input type="submit" value="Submit">
</form>
</body>
</html>

postpro.php:

Code: [Select]
<?php
if ($_POST[&#39;title&#39;] == &#39;&#39; || $_POST[&#39;text&#39;] == &#39;&#39; || $_POST[&#39;user&#39;]) {
echo "You did not fill out the entire form";
die();
} else {
require(
"func.php");

$title $_POST[&#39;title&#39;];
$text $_POST[&#39;text&#39;];
$author $_POST[&#39;user&#39;];

$date date("l, F d, Y");

mysql_query ("INSERT INTO `blog_entries` ( `id` , `date` , `author` , `title` , `entry` )
VALUES (
&#39;&#39;, &#39;
$date&#39;, &#39;$user&#39;, &#39;$title&#39;, &#39;$text&#39;
);"
);

echo 
"Post successful!";
}
?>


edit.php:

Code: [Select]
<?php
require("func.php");

$qResult mysql_query("SELECT * FROM blog_entries ORDER BY id DESC");

$counting mysql_num_rows($qResult);
if (
$counting == 0) {
echo 
"<H2>No blog posts.</H2>";
}

while(
$row mysql_fetch_array($qResult)) {
$title $row[&#39;title&#39;];
$id $row[&#39;id&#39;];
echo "
$title [<a href=&#39;editpost.php?id=$id&#39;>Edit</a>]
<BR>"
;
}
?>

« Last Edit: February 24, 2012, 06:38:07 pm by Niek »
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.066 seconds with 39 queries.