Google Community
Latest Forums Rules Resources
Custom Search

Go Back   Google Community > Webmaster Forums > Web Design, Coding & Programming Forum

GoogleCommunity Sponsor
Cirtex Hosting
Use coupon "forum" for 50% Off!

Reply
 
LinkBack Thread Tools Display Modes
Old 06-13-2005, 05:53 PM   #1 (permalink)
Noogle
 
Join Date: Jun 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Uncared
Create Your Own Blog System!

This tutorial wills how you how to make a blog system.

IMPORTANT: Read the orange // comments when in Dreamweaver or w/e you use.

Part 1: MySql Query, run this query in phpMyAdmin interference if avaiable.
PHP Code:

CREATE TABLE blogs (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(75),
username VARCHAR(75),
mood VARCHAR(50),
blog LONGTEXT,
date VARCHAR(75),
PRIMARY KEY(id)
);


Part 2: Copy edit and save as addblog.php
PHP Code:

<?

//assign variables for dbconnect
//change to your preferences
$dbhost = 'localhost';
$dbname = 'database';
$dbuser = 'user';
$dbpasswd = 'password';

//connect to database
$cid = mysql_connect($dbhost,$dbuser,$dbpasswd);
mysql_select_db($dbname);
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

?>

<h2> Add Blog Entry </h2>

BBCode is on

<?


//this is processed when the form is submitted
//back on to this page (POST METHOD)
if ($_SERVER['REQUEST_METHOD'] == "POST")
{

//escape data and set variables, addslashes, str_replace
//no need to change anything unless desired
$id = addslashes($_POST["id"]);
$name = addslashes($_POST["name"]);
$username = addslashes($_POST["username"]);
$mood = addslashes($_POST["mood"]);
$date = date("F j, Y");
$blog = addslashes($_POST["blog"]);
$blog = str_replace("<", " < ", $blog);
$blog = str_replace("\n", "
", $blog);
$blog = str_replace("<?php", " <?php ", $blog);
$blog = str_replace("", " ", $blog);
$blog = str_replace("", "
", $blog);
$blog = str_replace("", " ", $blog);
$blog = str_replace("", "
", $blog);
$blog = str_replace("", " <u> ", $blog);
$blog = str_replace("", " </u> ", $blog);
$blog = eregi_replace(
'\([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\',
'1', $blog);
$blog = eregi_replace(
'+)]'.
'([-_./a-zA-Z0-9 !&%#?+$,\'"=:;~]+)\',
'\\2', $blog);
$blog = eregi_replace(
'\[img]([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\[/img]',
'[img]\\1[/img]', $blog);


//setup SQL statement
//get data ready
//no need to change anything, unless change above
$sql = " INSERT INTO blogs ";
$sql .= " (id, name, username, mood, date, blog) VALUES ";
$sql .= " ('$id','$name','$username','$mood','$date','$blog' ) ";

//execute SQL statement
$result = mysql_query($sql, $cid);

//if mysql error, say what it was
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
else
{

//if no error, and query was successful, say so
print "

Blog Entry Added Click here to view it.</p>\n";
}

}

//display form
?>
<font size="1" fontface=><form name="fa" action="addblog.php" method="POST">
<table>
<tr><td><font face="Trebuchet MS" size="1">Title: </font> <><td><input type="text" name="name" size=20 class="input"><><>
<tr><td><font face="Trebuchet MS" size="1">Username: </font> <><td><input type="text" name="username" size=20 maxlength="75" class="input"><><>
<tr><td><font face="Trebuchet MS" size="1">Mood: </font> <><td><input type="text" name="mood" size=20 maxlength="50" class="input"><><>
<tr><td valign=top><font face="Trebuchet MS" size="1">Blog Entry:
</font> <><td> <textarea name="blog" rows=16 cols=20 class="input"></textarea><><>

<tr><th colspan=2>

<input type="submit" value="Add Entry" class="button"></p></th><>
</table>
</form></font>

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


Explaination:

PHP Code:
//assign variables for dbconnect
//change to your preferences
$dbhost = 'localhost';
$dbname = 'database';
$dbuser = 'user';
$dbpasswd = 'password';

//connect to database
$cid = mysql_connect($dbhost,$dbuser,$dbpasswd);
mysql_select_db($dbname);
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

Just assigns variables connects to database. CHange the db variables and, leave rest the same if desired.

PHP Code:
//this is processed when the form is submitted
//back on to this page (POST METHOD)
if ($_SERVER['REQUEST_METHOD'] == "POST")
{

//escape data and set variables, addslashes, str_replace
//no need to change anything unless desired
$id = addslashes($_POST["id"]);
$name = addslashes($_POST["name"]);
$username = addslashes($_POST["username"]);
$mood = addslashes($_POST["mood"]);
$date = date("F j, Y");
$blog = addslashes($_POST["blog"]);
$blog = str_replace("<", " < ", $blog);
$blog = str_replace("\n", "
", $blog);
$blog = str_replace("<?php", " <?php ", $blog);
$blog = str_replace("", " ", $blog);
$blog = str_replace("", "
", $blog);
$blog = str_replace("", " ", $blog);
$blog = str_replace("", "
", $blog);
$blog = str_replace("", " <u> ", $blog);
$blog = str_replace("", " </u> ", $blog);
$blog = eregi_replace(
'\([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\',
'1', $blog);
$blog = eregi_replace(
'+)]'.
'([-_./a-zA-Z0-9 !&%#?+$,\'"=:;~]+)\',
'\\2', $blog);
$blog = eregi_replace(
'\[img]([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\[/img]',
'[img]\\1[/img]', $blog);

This pulls the variables from the posted content, and does changes to the strings.

PHP Code:
//setup SQL statement
//get data ready
//no need to change anything, unless change above
$sql = " INSERT INTO blogs ";
$sql .= " (id, name, username, mood, date, blog) VALUES ";
$sql .= " ('$id','$name','$username','$mood','$date','$blog' ) ";

//execute SQL statement
$result = mysql_query($sql, $cid);

//if mysql error, say what it was
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
else
{

//if no error, and query was successful, say so
print "

Blog Entry Added Click here to view it.</p>\n";
}

}

This part of the script adds the data to the database, and checks for mysql errors, if no errors it says succesfully added.

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

Part 3: Copy edit and save as blog.php, to access this go to http://domain.com/blog.php?username=yourusername
PHP Code:
<?


//assign variables for dbconnect
//change to your preferences
$dbhost = 'localhost';
$dbname = 'database';
$dbuser = 'user';
$dbpasswd = 'password';

//connect to database
$cid = mysql_connect($dbhost,$dbuser,$dbpasswd);
mysql_select_db($dbname);
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

?>

<?

//set $username variable
$username=$_POST['username'];

//assign variables to query database
//no need to change anything
$sql = " SELECT * FROM blogs ";
$sql .= " WHERE username = '$username' ORDER BY `id` DESC ";

//execute SQL statement
echo"$username's blog"; echo"

";
$rs = mysql_query($sql, $cid);
$result1 = mysql_query("SELECT * FROM blogs WHERE username = '$username' ");
if (mysql_error()) { print "Database Error: $sql " . mysql_error(); }

//if username is left blank, echo no user exists
//else continue
if($_GET["username"]==""){
die("No such user exists");
}
else
{

//pull row's
//no need to change anything
# display results
while ($row = mysql_fetch_array($rs))
{
$name = stripslashes($row["name"]);
$id = stripslashes($row["id"]);
$mood = stripslashes($row["mood"]);
$username = stripslashes($row["username"]);
$date = stripslashes($row["date"]);
$blog = stripslashes($row["blog"]);

//print's blog

print "
Title: $name

Added: $date

Mood: $mood<a name=\"$id\"></a>

Blog Entry:
$blog

\n

<hr noshade='noshade' color='#000000' size='1' />";

}
}

?>


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


Explanation:

The connect to database snippet is the same as above.

PHP Code:
//set $username variable
$username=$_POST['username'];

//assign variables to query database
//no need to change anything
$sql = " SELECT * FROM blogs ";
$sql .= " WHERE username = '$username' ORDER BY `id` DESC ";

//execute SQL statement
echo"$username's blog"; echo"

";
$rs = mysql_query($sql, $cid);
$result1 = mysql_query("SELECT * FROM blogs WHERE username = '$username' ");
if (mysql_error()) { print "Database Error: $sql " . mysql_error(); }

if($_GET["username"]==""){
die("No such user exists");
}


Assigns the username variable, and selects from the database table where the username equals the row. If no username was selected the display no username specified.

PHP Code:
else
{

//pull row's
//no need to change anything
# display results
while ($row = mysql_fetch_array($rs))
{
$name = stripslashes($row["name"]);
$id = stripslashes($row["id"]);
$mood = stripslashes($row["mood"]);
$username = stripslashes($row["username"]);
$date = stripslashes($row["date"]);
$blog = stripslashes($row["blog"]);

//print's blog

print "
Title: $name

Added: $date

Mood: $mood<a name=\"$id\"></a>

Blog Entry:
$blog

\n

<hr noshade='noshade' color='#000000' size='1' />";

}
}


This part fetchs the array of the table, and pulls rows from the database/stripslashes we added while adding the data. And prints the blog entrys.

If you find a error or problem in this site please send an email to [email]altereddesigns@gmail.com[/url] immediataly!

- Tutorial Written By Uncared -
Uncared is offline   Reply With Quote
 
Sponsored Links
Old 06-30-2005, 05:25 PM   #2 (permalink)
Googler
 
Join Date: May 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
pratik
how do you CSS template?
pratik is offline   Reply With Quote
Old 06-30-2005, 05:42 PM   #3 (permalink)
Microsoft Student Partner
Google Guru
 
darrenstraight's Avatar
 
Join Date: Jul 2004
Location: England
Posts: 5,787
Thanks: 0
Thanked 2 Times in 2 Posts
darrenstraight has disabled reputation
Nice tutorial Uncared, I'll have to try it out some time.
__________________
Visit my Tech Blog!
darrenstraight is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create an account? brum Gmail Forum 13 07-22-2007 11:42 PM
how to create a web server seomumbai Domain Name Forum 2 10-18-2006 07:24 PM
how to create this adsense? ? myinnet Google AdWords & AdSense Forum 6 08-02-2006 01:39 AM
Wich is the best Blog system for seo? auhlrich All About Google 6 03-30-2006 01:31 AM
How to create a favicon mustaq Web Design, Coding & Programming Forum 2 10-24-2005 08:10 AM


All times are GMT -8. The time now is 02:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© 2004–2007 Google Community