Google Community Chat
 
Create Your Own Blog System!

You're visiting Google Community as a guest.
In order to post, you'll need to register and log in.

(If you were registered and logged in, these advertisements wouldn't be here)
Post new topic   Reply to topic    Google Community Forum Index // Web Design, Coding & Programming Forum
   
Author Message
Uncared
Noogle
Noogle


Joined: 13 Jun 2005

387.05 GC$

Items

PostPosted: Mon Jun 13, 2005 5:53 pm    Post subject: Create Your Own Blog System! Reply with quote
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><br><br><b>BBCode</b> 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", " <br> ", $blog);
$blog = str_replace("<?php", " <?php ", $blog);
$blog = str_replace("", " <b> ", $blog);
$blog = str_replace("", " </b> ", $blog);
$blog = str_replace("", " <i> ", $blog);
$blog = str_replace("", " </i> ", $blog);
$blog = str_replace("", " <u> ", $blog);
$blog = str_replace("", " </u> ", $blog);
$blog = eregi_replace(
'\([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\',
'<a href="\\1" target="_blank">1</a>', $blog);
$blog = eregi_replace(
'+)]'.
'([-_./a-zA-Z0-9 !&%#?+$,\'"=:;~]+)\',
'<a href="\\1" target="_blank">\\2</a>', $blog);
$blog = eregi_replace(
'\[img]([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\[/img]',
'<img src="\\1" border="0" alt="User Posted Image" />', $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 "<p><b>Blog Entry Added Click <a href='http://domain.com/blog.php'>here</a> to view it.</b></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"><b>Title: </b> </font> </td><td><input type="text" name="name" size=20 class="input"></td></tr>
<tr><td><font face="Trebuchet MS" size="1"><b>Username: </b> </font> </td><td><input type="text" name="username" size=20 maxlength="75" class="input"></td></tr>
<tr><td><font face="Trebuchet MS" size="1"><b>Mood: </b> </font> </td><td><input type="text" name="mood" size=20 maxlength="50" class="input"></td></tr>
<tr><td valign=top><font face="Trebuchet MS" size="1"><b>Blog Entry: </b>
</font> </td><td> <textarea name="blog" rows=16 cols=20 class="input"></textarea></td></tr>

<tr><th colspan=2><p><input type="submit" value="Add Entry" class="button"></p></th></tr>
</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", " <br> ", $blog);
$blog = str_replace("<?php", " <?php ", $blog);
$blog = str_replace("", " <b> ", $blog);
$blog = str_replace("", " </b> ", $blog);
$blog = str_replace("", " <i> ", $blog);
$blog = str_replace("", " </i> ", $blog);
$blog = str_replace("", " <u> ", $blog);
$blog = str_replace("", " </u> ", $blog);
$blog = eregi_replace(
'\([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\',
'<a href="\\1" target="_blank">1</a>', $blog);
$blog = eregi_replace(
'+)]'.
'([-_./a-zA-Z0-9 !&%#?+$,\'"=:;~]+)\',
'<a href="\\1" target="_blank">\\2</a>', $blog);
$blog = eregi_replace(
'\[img]([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\[/img]',
'<img src="\\1" border="0" alt="User Posted Image" />', $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 "<p><b>Blog Entry Added Click <a href='http://domain.com/blog.php'>here</a> to view it.</b></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"<b>$username's blog"; echo"</b><br /><br />";
$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<br><br>Added: $date<br /><br />Mood: $mood<a name=\"$id\"></a><br><br>Blog Entry:<br> $blog<br /><br />\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"<b>$username's blog"; echo"</b><br /><br />";
$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<br><br>Added: $date<br /><br />Mood: $mood<a name=\"$id\"></a><br><br>Blog Entry:<br> $blog<br /><br />\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 altereddesigns@gmail.com immediataly!

- Tutorial Written By Uncared -
Back to top
View user's profile Send private message
pratik
Rusty
Googler


Joined: 12 May 2005

1320.80 GC$

Items

PostPosted: Thu Jun 30, 2005 5:25 pm    Post subject: Reply with quote
how do you CSS template?
Back to top
View user's profile Send private message
darrenstraight
Site Admin & Platinum Member
Site Admin & Platinum Member


Joined: 25 Jul 2004
Location: England
173385.09 GC$

Items

PostPosted: Thu Jun 30, 2005 5:42 pm    Post subject: Reply with quote
Nice tutorial Uncared, I'll have to try it out some time.
_________________
My Blog | Microsoft Discussion
Back to top
View user's profile Send private message Visit poster's website
Sponsored Links
Posted: 5 Dec 2008 10:35 am    Post subject: Advertisements
Back to top
Post new topic   Reply to topic    Google Community Forum Index // Web Design, Coding & Programming Forum All times are GMT - 8 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Host your free forums with Invision Plus.net forum web hosting with your own subdomain.

alexisBlue v1.2 // Theme Created By: Andrew Charron // Icons in Part By: Travis Carden

© 2005-2006 Google Community

Powered by phpBB

Privacy Policy | Contact Us

Powered by Google Search blog

This website is not affiliated in any way with Google, Inc.
Google™ is a registered trademark of Google, Inc.