Jul 25, 2008

Personal Blog - [ Database Required ]

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Personal Blog - [ Database Required ]

Neutrality
Okay, after a week, I have successfully created a personal web blog.
I first created it using a flat text file, I but realized that it was just too limited like that. So, I redid it in a database-compatible manner.

NOTES:

CODE

- This blog does not support comments yet. If you want, you can build
 on this script by creating a comment system as well. I may also  
 update it with a comment system in the future.

- You should have an average to intermediate knowledge of MySQL  
 commands and database manipulation in general, especially if you  
 want to add a comment system to it.

- There are three files: BLOG.INC, ADDENTRY.INC, and MESSAGES.INC.


CODE

BLOG.INC

/* Use this as an include in one of your webpages, preferrably not on  one visible to the public */

/* Replace [ page url ] with the name of the page you want to send the data to [ ie. index.php ] */

<?php

echo "<table width=100%>";
echo "<form action=[ page url ] method='post'>";
echo "<tr><td width=20%><font>Name:</font></td>";
echo "<td width=80%><input type='text' name='name'></td></tr>";
echo "<tr><td width=20%><font>Title:</font></td>";
echo "<td width=80%><input type='text' name='title'></td></tr>";
echo "<tr><td width=20%><font id='content1'>Message:</font></td>";
echo "<td width=80%><textarea name='message'></textarea></td>
     </tr>";
echo "<tr><td colspan=2><center><input type='submit' name='blog'  
     value='Post!'></center></td></tr>";
echo "</form></table><br>";

?>


CODE

ADDENTRY.INC

/* Use this as an include in the page that will be accepting this information */

/* Substitute <server> with the name of the server [ which is usually "localhost" ], <username> with your database username, <password> with your database password, and <database> with the name of your desired database. */

<?php

if(isset($blog))
{
    $dbase = mysql_connect (<server>, <username>, <password>);
    mysql_select_db (<database>);

    $todaysDate = getdate();
    $date = $todaysDate[weekday]." ".$todaysDate[month]." ".
            $todaysDate [mday].", ".$todaysDate[year];

    $todaysTime = getdate();
    $realHours = $todaysTime[hours] + 3;
    $time = $realHours.":".$todaysTime[minutes].":".$todaysTime[seconds];

    $createEntry = "INSERT INTO blog(id, name, title, message, date, time,  
    comments) VALUES(NULL, '$name', '$title', '$message', '$date',
    '$time', 0)";

    mysql_query($createEntry);

    mysql_close($dbase);
}

?>


CODE

MESSAGES.INC

/* Use this as an include in the page that will be displaying the Blog entries to the public */

/* Substitute <server> with the name of the server [ which is usually "localhost" ], <username> with your database username, <password> with your database password, and <database> with the name of your desired database. */

$dbase = mysql_connect (<server>, <username>, <password>);
mysql_select_db (<database>);

$dbase = mysql_connect ("localhost", "proxima_chris", "gh62jj");
mysql_select_db ("proxima_myblog");

$findInfo = mysql_query("SELECT id, name, title, message, date, time,  
           comments FROM blog");

for($n=mysql_num_rows($findInfo)-1; $n>=0; $n--)
{
   mysql_data_seek($findInfo, $n);
   
   list($id, $name, $title, $message, $date, $time, $comments) =
        mysql_fetch_row ($findInfo);
   echo "<table width=100% bgcolor=#000000 cellpadding=5 border=1
        bordercolor=#444444><tr><td bordercolor=#000000 name='entry'>";
   echo "<font>#".$id."</font>  ";
   echo "<font>".$title."</font><br>";
   echo "<hr width=100%></hr>";
   echo "<font>".$message."</font><br><br>";
   echo "<hr width=100%></hr>";
   echo "<font>Posted by ".$name." on ".$date." at ".$time.
        "</font><br>";
   echo "</td></tr></table><br>";  
}  

mysql_close($dbase);  

?>



You have any questions, concerns, suggestions, or if you need further clarification/support feel free to post here and make yourself heard. I don't bite. tongue.gif

 

 

 


Reply

slu
I justed skimmed your code, and one thing I would suggest is using a template system. This would make your blog more flexible and maintainable (getting rid of all the ugly echo "<...>" lines).

I've used Smary for several projects, and it's really cool - fast and simple. See http://smarty.php.net/


Reply

snlildude87
I second the template comment by stu. I just finished applying the new layout for my site, and if I had a template engine, it would have taken much less because the only thing I had to do when editing my pages was to move text around, and that took weeks.

By the way, where can we see your new creation? What is its URL?

Reply

slu
QUOTE(snlildude87 @ Jun 28 2005, 01:43 AM)
I second the template comment by stu. I just finished applying the new layout for my site, and if I had a template engine, it would have taken much less because the only thing I had to do when editing my pages was to move text around, and that took weeks.
*



If doing a redesign of a complete site PHP-Mesh is the way to go. You can change the layout without changing your original files! PHP-Mesh inserts code before and after all php/html pages and takes the html apart and puts it together again. You describe how to put your page back together again (i.e. the (new) layout) with one or more Decorator classes. A simple decorator would look like this:

CODE

<html>
 <head>
   <title>MySite :: <?php $page->title(); ?></title>
   <?php $page->head(); ?>
 </head>
 <body>
   <h1><?php $page->title(); ?></h1>
   <?php $page->body(); ?>
 </body>
</html>


In the above example all pages will get a title that starts with "MySite :: " and the title of the page is repeated in a H1 at the beginning. There's an $page object available in all Decorators, it contains methods corresponding to html-tags. Each method returns the contents from the original page. As the Decorators are just php files you can do all kinds of coding (like switching designs on certain pages).

It's awesome and seems like magic...

See http://trypticon.org/software/phpmesh/

The concept is based on SiteMesh, which does a similar thing for Java-based web sites.

 

 

 


Reply

Neutrality
Yeah, I've seen software like that before. IPB uses that template system as well [ or at least I think it does ]. I could use something like that. Typing out all of those "echo" statements was hellish and tedious. I'll consider it.

Oh, and here is how the blog looks [ *NOTE: This is my website's blog, it's coded in the exact same way save for the stylesheet classes ]:

Neutrality's Blog

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : personal, blog, database, required

  1. Ms-access Database Question
    Allowing Web Access to the Informaton (3)
  2. How Do I Connect To Live Database With Php Script?
    while being hosted with ComputingHost (6)
    I am not new to programming. I want to create a form to add some values into my tables, the code
    are all working. But I am not sure what is the URL to connect to my site's database. All along,
    I have been testing through MAMP, which provides a local copy of mySQL. Can anyone lend me a hand?
    My site's URL is http://limetouch.com/ ....
  3. Script Help Required: Undefined Variable
    A fault I cannot spot in PHP (3)
    Hi, when running a PHP script I keep getting the error: QUOTE Notice: Undefined variable: bret
    in c:\program files\easyphp1-8\home\poll.php on line 294 Notice: Undefined
    variable: bret in c:\program files\easyphp1-8\home\poll.php on line 294 (And,
    yes, I get it twice). The code related to the variable is as follows: CODE function
    LogString($string,$type)     {         $t_log = "\n";
            $t_log .=
    $this->globaldata->server_vars['REMOTE_ADDR']."....
  4. Making Sure They Did Not Leave Any Required Fields Blank
    (3)
    how to make sure they did not leave any required fields blank? CODE <?php
        include("config/config.inc.php");
        include("config/dbcon.php");     include("checksession.php");
                 if(isset($_POST['action'])){         $gname =
    $_POST['gname'];         $gemail = $_POST['mail'];
            $gmsg = $_POST['gmsg'];         $date =
    date("m.d.y"); $sql = "insert into tblg....
  5. What Coding Languages Are Required?
    (5)
    I want to add a feature in my website so that users can make a professional -looking resume-like web
    page. It will be like a form based series of questions that visitor ll need to answer.Based on this
    a webpage as prescribed in pre-defined template ll be created .I want to know to do this what
    languages are used? I want some suggestion regarding this.My site is currently on Joomla platform.
    thanks in advance....
  6. Connecting Php Site To Database
    (6)
    Please Help Me with this site's error http://gatewaybiz.x10hosting.com/surf/ ....
  7. Can Database Column Names Start With A Number?
    Can database column names start with a number? (1)
    Can database column names start with a number or must they start with a letter like php vars? Like
    my_table.1fieldname ? Does this vary from db system to db system? Is it considered good/bad form? ....
  8. Auto Pruning An Sql Database With Php
    How can i do this? (4)
    Hey all. Now i have a DB, an SQL DB, and i need to auto prune the data there to delete rows lder
    than a certain time, lets say 2 months for now, the question is how do i do this? The obvious thing
    is just to add a field which is the numerical representation of the month when the data is entered
    and every time the DB is accessed it will check this number against the current month,in a numerical
    format, and if the difference is two or greater that row is deleted, so if the month is January, it
    would be O1 and if the current month is march then it would be O3 and the diff....
  9. Read Xml And Import Into Database
    question (2)
    hi all , i have one big problem i need to know , how i can read xml file and then save strings in
    xml in database for example its my xml CODE <?xml version="1.0"?>
    <numbers> <arash>1</arash> <kiarash>2</kiarash>
    </numbers> i want my soruce read this xml file and then save string into arash field in
    mysql database for example in this source arash string is " 1" and kiarash string is "2" my fields
    in mysql are standard and we have 2 field with names "arash" and "kiarash" please help me , if yo....
  10. A Free Php Blog Script
    help (8)
    Do you know some free php scripts that I 'administrator' can post articles and so the
    visitors can put comments on these articles "just like Yahoo here ", I've searched scripts like
    this but I didn't find them I tried joomla and mambo but thes can only post articles but
    can't let the members or visitors to put comments on it.....
  11. Download Database Backup
    Download Database Backup (0)
    Hi all i want write backup system like Phpmyadmin export in single file , my question is what is
    backup query ? i must write manul query for backup for example loop query to get string form
    database and write into one file or php have backup query ? thanks /wink.gif"
    style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> ....
  12. Editing Information In A Mysql Database And Deleting Rows
    (5)
    I need help with a couple of things. First, I need to know how to retrieve information from a mysql
    database and edit it then re add it to the database. I also would like to know how to easily delete
    a mysql row. And I want this done without going to phpMyAdmin. Thanks for the help!....
  13. Importing .csv Into Mysql Database
    NEED HELP! (6)
    I need help importing a .csv contents into a Mysql database. I have this. But its not working.
    CODE <?php connection = mysql_connect("******", "**********",
    "********") or die ("Unable to connect to server"); $db =
    mysql_select_db("b9_259782_CC", $connection) or die ("Unable to select
    database"); fopen ('csvranks.csv', 'r');
    mysql_query("INSERT INTO test_table (id, name, guild, level, exp) ?> What
    am I doing wrong? The mys....
  14. How To Delete A Row In Mysql.
    A very simple help required (4)
    Im using the following code, for very simple work.. it simply gets and print the comments which are
    stored in the database. Now it will show like comment 1. comment 2. comment 3. etc etc i want to
    add 'delete' option that i can delete any comment. it displays like comment 1.
    Delete comment 2. Delete comment 3. Delete
    So that when i click on delete, it simply deletes the comment and print the remaining comments. Its
    very simple. i hope you understand. QUOTE $result = mysql_query("sele....
  15. Files Required?
    (5)
    I want to learn php and I am already on the first steps to doing it. I have set up my server using
    easyPHP as well as XAMPP which is a package containing FileZilla, Apache and MySQL. Other than
    easyPHP, XAMPP and MySQL, what other softwares are required to be set up for me to successfully
    learn how to program with PHP?....
  16. Php Search Engine Script For Mysql Database
    (11)
    A search engine is provided to facilitate the user with undemanding and clear-cut search options.
    The search facility includes simple search, search by title, search by word/phrase, ect… Thus, the
    user is at a safe distance from the risk of selecting files/folders ambiguously. In addition, a
    history of recent searches can be preserved for future perusal. Now
    day’s visitors have a large option for his needs on internet and so visitors are not vesting their
    time by following the dead links on your site. So a search engine is essential for your....
  17. Problem To Join Tables In Database
    Problem in joining (many to many) relation (3)
    Please help me. I'm building a group of database fro a program. the situation is like this:
    'user' may have 1 or more class(es). 'class' itself may have 1 or more user in its
    classroom. I'm bad at explaining... maybe like this: A program is made to write data of
    classroom. Hikaru has a math class at Monday and statistic class at Tuesday. The math class itself
    consists of about 50 students in a classroom. So, Hikaru (user ) may have one or more class at
    time, math class (class) may have one or more students at time. So, basically I must mak....
  18. File In Database
    Question.thanks (1)
    Hi all i write this code i want when you see download.php (this code) my file goes for download for
    user sorry my english is not very good its a file database project for my university but when i
    browse this code my soruce file (.zip) echo in my page and dont goes for download my next querstion
    about safe mode i saw (php.net and zend) when safemode is on file databaseing and header() is not
    working . is it true ? if is it true i save my file at hosting and no (database) i want write
    standard script . plz help me thanks more and more CODE include("config.php&....
  19. Code To Install Mysql Database Table?
    (5)
    Can anyone show me example code of how to install a database table instead of me having to upload an
    file with it in, so i can do it from a php page? Thanks in advance ;-)....
  20. Showing Numbers Of Mysql Entries In A Database Table
    It should be easy, but I don't know how... (7)
    I have a database, and need to know how to show the numbers of entries. So, if there are 10 entries
    in the selected database table, it will show the number 10 . I'm pretty sure this should be
    easy, but I don't know how to do it. Can someone tell me? /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  21. Php Code Fix Required
    URGENT (3)
    I am running a Web Chat and need to get this to display the User IP to them, but this code isnt
    working. CODE <PARAM NAME="welcomemessage" VALUE="<?php
    echo  $_SERVER['REMOTE_SERVER'];" has been logged. Chat powered by
    GCN"> Any help would be extremly grateful. Thank you Inserted the code in CODES tag ....
  22. Some Php Functions Explaination Required
    (2)
    Can some one please tell me what is the purpose of the following functions , although there's a
    little explaination with everyline but i cant understand, can some one exaplin it bit clearly and
    tell me that why it is needed in config.inc.php.. what is its purpose and will it work if i dont
    include these files in config.inc.php thanks QUOTE ### Url were Website has been installed, not
    '/' in end! define('C_URL','http://www.test.com/Website'); ### Internal
    path to Website directory define('C_PATH','Z:/home/www.test.com/www/....
  23. Crontab Automated Database Backup
    using crontab to make automated database (2)
    i'd like to make an automated database backup as following: 1- i would like to optimize my
    databse's tables. 2- I would like to remove any existing backup tarfile. 3- I dump the database
    to a /tmp file. 4- I tar the database dump and then delete it. i wrote the following shell: CODE
    #!/bin/sh rm -rf /tmp/mybackup.sql.tgz mysqldump -uroot -pmypass --opt mybackup >
    /tmp/mybackup.sql.backup cd /tmp/ tar -zcvf mybackup.sql.tgz mybackup.sql.backup rm -rf
    /tmp/mybackup.sql.backup ....
  24. Login / Authetication System Using Database
    adding information (4)
    Is there any way to make such database where I can write like name and passwords.. Then make an
    login box, and when somebody trys to acces the login he needs to write the name and password.. Then
    it is verifyed if is there such name and password and if it is then acces the page.. I think there
    is posible something like that with MySQL (db).. but can anybody say me a script or way to make
    something like that? Alredy thanks......
  25. Can You Add Images Into A Mysql Database?
    Using Php? (20)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  26. Is Doing The Whole Database / Php Thing Worth It?
    Question from the inexperianced... (13)
    I'm planning on a site redesign, and I'm going to add some very basic php includes in there,
    because I've managed to figure out how to do them. I wanted to use them to do includes of my
    navigation, so I'd only have to update in one place when new links are added, as opposed to
    having to update several pages all at once. I'm not sure what else php can be used for, and I
    did a search on it, and it pretty much all said includes and databases. Well, databases, I
    don't know how to make, and I was wondering if it's really worth my time to figure i....
  27. Database Extraction Layer
    Does php has Database extraction layer? (1)
    Hi PHP geeks, Do you know if php has Database extraction layer? like Java has. Which is used for
    development of database layer, so it become easy to change the database if you wish to without
    modifying so much code underneath.... Any ideas is welcome. I am sure there should be something
    which is being used and reliable and mature. I am new to PHP so want to use it if it is there. Good
    to know from experienced developer about there developing experience. Thanks in advance.....
  28. Script That Deletes A Row In A Mysql Database Usin
    (1)
    I have just made a script that deletes a row in a mysql database using an image as a button.
    However it will only work in FireFox and not in IE. Can any one see away around this and help me
    root out the problem. This is the script in short: PHP Code: CODE $query_products =
    "SELECT * FROM manufacturer ORDER BY name ASC";
    include('external_files/pagination.php');    // If the form was submitted, delete
    the items selected from the database
    if(isset($_POST['delete'])){  $query = 'DELETE FRO....
  29. Help Importing Mysql Database Results
    Need help formatting link (3)
    I am having trouble formatting my table to display the results of a mySQL query the way I want.
    Here is the part of my code: CODE $result = mysql_query("SELECT * FROM uploads
    WHERE Category='Drama'") or die(mysql_error()); ?> <table
    cellspacing="2" cellpadding="2"> <tr> <th>Title</th>
    <th>Author</th> <th>File</th></tr> <?php // keeps
    getting the next row until there are no more to get while($row = mysql_fetch_array....
  30. Writing To Database Problem With Mysql - Not Writing Forum Post
    (3)
    I'm making a forum and I've had several problems tonight which I've come here to ask
    then found the answer to myself, but this one is stumping me. Whenever it goes to write the post to
    the database, it saves the poster, and the time, but the part where the message would go is empty.
    Here's the code, with comments about what it's supposed to do (what I wanted it to do and
    thought it did): CODE $imsg = stripslashes($_POST['msg']);
    //Get message if(strlen($imsg) > 5 && strlen($imsg)....

    1. Looking for personal, blog, database, required

Searching Video's for personal, blog, database, required
Similar
Ms-access
Database
Question -
Allowing Web
Access to
the
Informaton
How Do I
Connect To
Live
Database
With Php
Script? -
while being
hosted with
ComputingHos
t
Script Help
Required:
Undefined
Variable - A
fault I
cannot spot
in PHP
Making Sure
They Did Not
Leave Any
Required
Fields Blank
What Coding
Languages
Are
Required?
Connecting
Php Site To
Database
Can Database
Column Names
Start With A
Number? -
Can database
column names
start with a
number?
Auto Pruning
An Sql
Database
With Php -
How can i do
this?
Read Xml And
Import Into
Database -
question
A Free Php
Blog Script
- help
Download
Database
Backup -
Download
Database
Backup
Editing
Information
In A Mysql
Database And
Deleting
Rows
Importing
.csv Into
Mysql
Database -
NEED
HELP!
How To
Delete A Row
In Mysql. -
A very
simple help
required
Files
Required?
Php Search
Engine
Script For
Mysql
Database
Problem To
Join Tables
In Database
- Problem in
joining
(many to
many)
relation
File In
Database -
Question.tha
nks
Code To
Install
Mysql
Database
Table?
Showing
Numbers Of
Mysql
Entries In A
Database
Table - It
should be
easy, but I
don't
know how...
Php Code Fix
Required -
URGENT
Some Php
Functions
Explaination
Required
Crontab
Automated
Database
Backup -
using
crontab to
make
automated
database
Login /
Autheticatio
n System
Using
Database -
adding
information
Can You Add
Images Into
A Mysql
Database? -
Using Php?
Is Doing The
Whole
Database /
Php Thing
Worth It? -
Question
from the
inexperiance
d...
Database
Extraction
Layer - Does
php has
Database
extraction
layer?
Script That
Deletes A
Row In A
Mysql
Database
Usin
Help
Importing
Mysql
Database
Results -
Need help
formatting
link
Writing To
Database
Problem With
Mysql - Not
Writing
Forum Post
advertisement



Personal Blog - [ Database Required ]



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE