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:
<?php
Now we need four variables:
Host, Username, DB, and Password:
$db ='yourdb'
$host ='localhost';
$username ='yoursite_username';
$pass ='yourpass';
(change to fit your DB settings)
now, the code that connects
$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:
?>
Now we're done with the first page, now time to build the ADMIN section.
under admin section
Create a page called index.php
<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:
<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:
<?php
if ($_POST['title'] == '' || $_POST['text'] == '' || $_POST['user']) {
echo "You did not fill out the entire form";
die();
} else {
require("func.php");
$title = $_POST['title'];
$text = $_POST['text'];
$author = $_POST['user'];
$date = date("l, F d, Y");
mysql_query ("INSERT INTO `blog_entries` ( `id` , `date` , `author` , `title` , `entry` )
VALUES (
'', '$date', '$user', '$title', '$text'
);");
echo "Post successful!";
}
?>
edit.php:
<?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['title'];
$id = $row['id'];
echo "
$title [<a href='editpost.php?id=$id'>Edit</a>]
<BR>";
}
?>