Blog Using Php: Files Or Mysql?

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Blog Using Php: Files Or Mysql?

leiaah
I've been planning to put up a blog on my site but I'm having trouble with how I should do it. I don't really know how blogs are made. Is it a database or a flat file? I know how to write to a file using PHP but I still don't know how to put the last entry on the top of the file. That's a big issue in the shoutbox I made for my site. If you look at it, the shouts keep appending at the end of the file and I want it to be on top.

Can anyone help me please? It would be nice if you'd give me detailed instructions on how to put it up, with files or with MySQL.

Reply

bjrn
If you want a blog, I suggest that you use one of the systems available from your cPanel. Or some other already existing system you can upload to your account. Building your own blogging system from scratch can of course be fun if you're into that sort of thing and want to do loads of things with PHP (and perhaps MySQL).

Reply

mobious
if you will just store blogs, you can just use flat files but for other stuff that has a high overhead such as login sessions, you better use mysql. but if you start to experience stuff like no read or write permission be of high overhead thats\'s the time you switch to mysql.

Reply

bjrn
MovableType is pretty neat in the way it builds static pages from your database. So when you post a new entry it builds a static index.html file, which doesn't need to get loads of things from your database.

Reply

Mike
Hmm.. You could always use one of the blog things in the cPanel but if you want to make one from scratch, I could help you. I made one from scratch for my site.

CODE

<?php

mysql_connect('localhost,'DBUSER','DBPASS');
mysql_select_db('DBNAME');

?>
<html>
<head>
<title>My Blog</title>
</head>
<body bgcolor="#999999">
<font color="black">
<body>
<table border=".01">
<tr bgcolor="#373737">
<td align="center" colspan="10"><b><i>RETURN TO:</i> [LINKS TO OTHER PLACES</b></td>
</tr>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<tr bgcolor="black">
<td>
<b><font color="white">Entry Title:</font></b>
</td>
<td>
<input type="text" name="blog_title" />
</td>
</tr>
<tr bgcolor="white">
<td>
<b>Entry Date:</b>
</td>
<td>
<input type="text" name="blog_date" />
</td>
</tr>
<tr bgcolor="black">
<td>
<b><font color="white">Current Mood:</font></b></td>
</td>
<td>
<input type="text" name="blog_mood" />
</td>
</tr.
<tr bgcolor="white">
<td>
<b>Blog Entry:</b>
</td>
<td>
<textarea name="blog" rows="15" cols="30"></textarea>
</td>
</tr>
<tr bgcolor="black">
<td>
<input type="submit" name="new_entry" value="Submit Entry!" />
</td>
<td>
<input type="reset" value="Reset" />
</td>
</tr>
</form>
</table>
<?php

if(isset($_POST['new_entry'])) {

mysql_query("INSERT INTO blog SET title='{$_POST['blog_title']}',date='{$_POST['blog_date']}',mood='{$_POST['blog_mood']}',entry='{$_POST['blog']}'") or die(mysql_error());

echo '<tr bgcolor="red" colspan="10"><td><b><font color="blue">Entry submitted.</font></b></td></tr>';

} else {

echo '';

}

?>
</body>
</font>
</font>
</html>



SAVE THAT FILE AS blog.php

--MySQL--

CREATE TABLE `blog` (
  `id` int(10) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `date` varchar(255) NOT NULL default '',
  `mood` varchar(255) NOT NULL default '',
  `entry` text NOT NULL default '',
  PRIMARY KEY(`id`)
)   TYPE=MyISAM;




TO POST THE BLOG ENTRIES ON YOUR SITE


<?php

mysql_connect('localhost','DBUSER','DBPASS');
mysql_select_db('DBNAME');

$query=mysql_query("SELECT title,date,mood,entry FROM blog ORDER BY id DESC");
while($row=mysql_fetch_row($query)) echo '<table border=".01" align="center"><tr><td><b><big>'.$row[0].'</big></b></td></tr><tr><td><b>Mood:</b> '.$row[2].'</td></tr><tr><td>'.$row[3].'</td></tr><tr><td>---------------<br /><small><b>Posted On:</b> '.$row[1].'</small></td></tr></table>';

?>


^^PUT THAT ON THE PAGE YOU WANT THE ENTRIES TO SHOW UP ON



You should edit the bgcolors/colors because I made that in case your site did not run on a CSS.

if it did, include this under <head>

<link rel="stylesheet" type="text" href="STYLESHEETNAME.css" />


then edit the tables and <font color>s and <body bgcolor> and <tr bgcolor> tags.

 

 

 


Reply

haron
I work on one project and my aplication (Web PHP aplication) must work with txt files, because MySQL is not safe (losing and changing data). It's interesant, all forum is based on MySQL.

If you want make blog from scratch, don't. Download any blog, and edit.

Reply

leiaah
QUOTE(Mike @ Mar 17 2005, 05:36 AM)
Hmm..  You could always use one of the blog things in the cPanel but if you want to make one from scratch, I could help you.  I made one from scratch for my site.

CODE

<?php

mysql_connect('localhost,'DBUSER','DBPASS');
mysql_select_db('DBNAME');

?>
<html>
<head>
<title>My Blog</title>
</head>
<body bgcolor="#999999">
<font color="black">
<body>
<table border=".01">
<tr bgcolor="#373737">
<td align="center" colspan="10"><b><i>RETURN TO:</i> [LINKS TO OTHER PLACES</b></td>
</tr>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<tr bgcolor="black">
<td>
<b><font color="white">Entry Title:</font></b>
</td>
<td>
<input type="text" name="blog_title" />
</td>
</tr>
<tr bgcolor="white">
<td>
<b>Entry Date:</b>
</td>
<td>
<input type="text" name="blog_date" />
</td>
</tr>
<tr bgcolor="black">
<td>
<b><font color="white">Current Mood:</font></b></td>
</td>
<td>
<input type="text" name="blog_mood" />
</td>
</tr.
<tr bgcolor="white">
<td>
<b>Blog Entry:</b>
</td>
<td>
<textarea name="blog" rows="15" cols="30"></textarea>
</td>
</tr>
<tr bgcolor="black">
<td>
<input type="submit" name="new_entry" value="Submit Entry!" />
</td>
<td>
<input type="reset" value="Reset" />
</td>
</tr>
</form>
</table>
<?php

if(isset($_POST['new_entry'])) {

mysql_query("INSERT INTO blog SET title='{$_POST['blog_title']}',date='{$_POST['blog_date']}',mood='{$_POST['blog_mood']}',entry='{$_POST['blog']}'") or die(mysql_error());

echo '<tr bgcolor="red" colspan="10"><td><b><font color="blue">Entry submitted.</font></b></td></tr>';

} else {

echo '';

}

?>
</body>
</font>
</font>
</html>
SAVE THAT FILE AS blog.php

--MySQL--

CREATE TABLE `blog` (
  `id` int(10) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `date` varchar(255) NOT NULL default '',
  `mood` varchar(255) NOT NULL default '',
  `entry` text NOT NULL default '',
  PRIMARY KEY(`id`)
)   TYPE=MyISAM;
TO POST THE BLOG ENTRIES ON YOUR SITE
<?php

mysql_connect('localhost','DBUSER','DBPASS');
mysql_select_db('DBNAME');

$query=mysql_query("SELECT title,date,mood,entry FROM blog ORDER BY id DESC");
while($row=mysql_fetch_row($query)) echo '<table border=".01" align="center"><tr><td><b><big>'.$row[0].'</big></b></td></tr><tr><td><b>Mood:</b> '.$row[2].'</td></tr><tr><td>'.$row[3].'</td></tr><tr><td>---------------<br /><small><b>Posted On:</b> '.$row[1].'</small></td></tr></table>';

?>
^^PUT THAT ON THE PAGE YOU WANT THE ENTRIES TO SHOW UP ON

You should edit the bgcolors/colors because I made that in case your site did not run on a CSS.

if it did, include this under <head>

<link rel="stylesheet" type="text" href="STYLESHEETNAME.css" />
then edit the tables and <font color>s and <body bgcolor> and <tr bgcolor> tags.
*




Thanks Mike! I'll try out the code! I figured I can make archives with these. smile.gif

Reply

OwrLam
I think better on file. My page stand on my script and works at 100 %

Reply

Mike
Dude, chill out. I think it would be better to use my code since it's easier to understand (most likely) than your file is. I have a file as well. Two actually, one is the actual blog; the other is view_blog.php . It switches to view_blog.php?user=USERIDOFUSER . So each user on my site gets their own blog. happy.gif Wait, where can I download your file though.. I want to check it out. I'll give you feedback. BTW- Did my code work?

Reply

mobious
well just a thought... why don't you guys make use of template systems? so that your code will be easy to understand because it get rid of all tags in the script. it's also much efficient.

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.

Similar Topics

Keywords : blog php files mysql

  1. Subquery In Mysql - (5)
    Is there anyway to make subqueries work in MySQL? I'm pretty certain someone out there knows
    how. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Can anyone help?
    CODE Select * from ITEMS where ID="Select Max(ID) from ORDERS"; This works
    for MSAccess and SQL Server but why not in MySQL? I'll be writing some reports and I've
    shifted database from MSAccess to MySQL. Help! Thanks....
  2. Increment A Mysql Column - how to increment a MySQL column one unit (7)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue....
  3. Html Form! - Using MySQL?! (4)
    Hey, I need your help again! I need some good working tutorial how I can update my SQL through
    HTML form. I did use some tutorials online found with the help of google; but they do not work
    properly; I mean there are still small mistakes. I need to have a good tutorial to follow. It
    should be based on security and more things. It has to be done in proper way......
  4. Mysql Won't Update - (4)
    Ok, so I'm making some arcade administration software so I don't have to add games the hard
    way, well anyway, one of the features I have is that on the homepage is a featured author and as
    such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
    varibles fine and the updating page recieves them because I echoed everything, then I build the
    query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
    database itself won't update even though all the varibles are there. Here's...
  5. Create Table - Mysql Code - Help - (1)
  6. Tools Needed! - PHP & MySQL (9)
    Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
    database on my laptop, instead checking them on a web-server which takes time....
  7. Mysql Error - (3)
    ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
    script, but i'm having a problem with the installer.php file, when it trys to inseret the user
    data into the database i keep getting the following error: CODE mySQL Error: You have an
    error in your SQL syntax; check the manual that corresponds to your MySQL server version for the
    right syntax to use near ';INSERT INTO `members` (`id`, `name`,
    `username`, `password`, `email`, `title`) ' at lin...
  8. Best Php And Mysql Editor For Noobs - anyone any php or mysql editor that is good for noob (6)
    hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
    if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
    ...
  9. Getting List Of Directories And Files Using Php - PHP Function for Directory and File List (6)
    is there a php function that lists the content of some folder.... example: /New folder new.txt
    left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
    style='vertical-align:middle' alt='rolleyes.gif' /> ...
  10. 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...
  11. Php And Mysql Programming - anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
    help guys...I want to make a simple program that will some values and then store them on a database
    and then retrieve them...uhmm let me give an example out put of what i need. This is the example
    say..: Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those
    are the data needed for input values...my question now is how can I make a database...
  12. Creating Profiles In Php/mysql ? - (7)
    i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
    that some user can register to my website , and after that he can Login and log out , and he can see
    his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />...
  13. Need Some Help In File Browser - listing all sub folders and files in them. (8)
    Hey I want to create a very simple file browser, so that, it reads all the sub-folders which are
    places in a directory, and the files inside the sub-folders (It reads only files inside sub-folders
    and list them in simply. ) Also, it creates a directory (any name) inside each sub folder. My
    Following code reads on the files inside the main directory, it does not read the files inside the
    sub-folders.. I appreciate any help. CODE <? $path = "./"; $dir_handle =
    @opendir($path) or die("Unable to open $path"); whil...
  14. Best Sites For Learning Php-mysql - (4)
    Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
    php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
    a better 1) but I wan't to know what is the best site for using php with mysql (using
    phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
    postgresql version of phpmyadmin whatever it's called looks better (visually)!...
  15. Download Script For Mp3 Files - (0)
    Hello, I'm looking for a download script for sound files (e.g. mp3, avi, wma, and other ones).
    i have found a few download scripts but they would not work for sound files for some reason. also
    this will not be used for allowing downloading of illegal or riped music, what i will be using this
    script for is i'm making a site for my church and the pastor wants to be able to recored the
    services and then have me upload them to the site so that the church members can download them for
    what ever reason. If some one could tell me how to make one or could show me a plac...
  16. Change Permission With Php Code - code to change files' and folders' permissions? (3)
    As everyone know, there two ways (that I can think of) to change files' and directories'
    permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
    client that supports chmod. Well, I'm doing something for my site that requires files to have
    full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
    the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
    alternative to doing this is to change each file permission myself, but that would be...
  17. Php + Mysql Question! - While inserting data into MySQL, how can I know if the data I'm in (4)
    Basically, I want to know if the Data I'm inserting through a Form is already there or not. Sort
    of a Username registration page. I have this, but it doesn't appear to work... CODE
    $result = mysql_query("SELECT * FROM users WHERE
    username='$username'"); if($result == 1)     {     echo
    '<h1>ERROR!</h1>The username you have chosen already exists!';     }
    ...
  18. [php/mysql]id Trouble [resolved] - (3)
    session_start(); include "database.php"; if (!$_SESSION || $_SESSION { // User
    not logged in, redirect to login page Header("Location: main.php"); } $result =
    mysql_query("select * from users order by id asc"); while($r=mysql_fetch_array($result))
    { $username=$r ; $info=$r ; $msn=$r ; $email=$r ;
    $id=$r ; $password=$r ; $userlevel=$r ; echo "
    user ID User Level U...
  19. [mysql/php]need Som Basic Help - (13)
    QUOTE session_start(); include "database.php"; include "edit.inc.php"; if (!$_SESSION
    ) { // User not logged in, redirect to login page Header("Location: main.php"); }
    if(isset($_POST )){ $email = $_POST ; $msn = $_POST ; $info =
    $_POST ; $updateemail = "UPDATE users SET email = '$email', msn =
    '$msn', info = '$info' WHERE username = '$username'";
    mysql_query($updateemail) or die("culd not edit your info"); echo "info updated"; } //
    Display log...
  20. 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...
  21. [mysql]get Id Of Loged In User? - (7)
    how to get the id number of the loged in user? my db is id. username. password. i have tryed a
    few things.. but i never seem to get it right /ohmy.gif" style="vertical-align:middle" emoid=":o"
    border="0" alt="ohmy.gif" />...
  22. Problem On Mysql "order By" - (5)
    Can someone please help...? I have a problem with using "ORDER BY" in mysql... CODE SELECT *
    FROM `foo` WHERE b='abc' ORDER BY 'number' ASC i want to sort the table out by
    the value in "number" which is a number.. but it came out to be sort by like this way...
    1->10->2->20 it only sort out the front digit.... but what i want is it will sort by how great the
    number is like this... 1->2->3........->10....->20 sorry my english isn't good enough...to
    describe my problem properly... hope you can understand and help me on this.....thx...
  23. Some Mysql Basics - (4)
    Greetings this tutorial will show you some mysql basics.. MySQL is one of the most used database. a
    simple config file at the top add this CODE <?php ?> after <?php add
    $username= "root"; // Username that has access to your database $password=
    ""; //Password that has access to your database $host = "localhost"; // The
    host where the database is (mostly this is localhost) $db = "databasename"; //
    The name of the database where you want to work with //connect to the database mysql_connect(...
  24. Php News Script - how to make news script that uses MySQL writen in PHP (19)
    How to make a News script with PHP + MySQL So..in this tutorial i will explain how to create PHP
    news script. first we have to create the table in My SQL.. with the code below you will do this (
    you have to enter it into SQL field ..in PHPmyADMIN) CODE CREATE TABLE news ( id
    int(10) unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title
    varchar(50) NOT NULL default '', content text NOT NULL, PRIMARY KEY (id),
    KEY postdate (postdate), FULLTEXT KEY content (content) ) >>...
  25. The Artists Tutorials :mysql Basic Commands - The Artists is an online programming unit and gfx designing clan. (0)
    Let's Talk about basic mysql commands used in php. I will now show you a list of the most common
    MySQL FUNCTIONS : QUOTE mysql_connect(MySQL server name,username,password) - opens a connection
    to a MySQL server. mysql_select_db(database name,connection id) - selects a database residing on
    the MySQL server. The database name parameter referes to an active database on the MySQL server that
    was opened with the mysql_connect function. The connection identifier is a reference to the current
    MySQL connection. mysql_query(sql query) - sends a query to the currently ac...
  26. Grabt Access To My Protected Files - grabt access to my protected files (2)
    Hi all, I am sure all of you are great programers but First i am no code programmer i am just
    trying to learn to run my sites, will the problem is i got a code from the web to protect my files
    ,1st i want to know how to work it out then i will try other things but can't let it go without
    a fight thanx all php: CODE <?php if ( ! defined( 'myname' )
    ) {         print "You cannot access this file directly.";         exit(); }
    customer data here ?> now i can't access my files what is the meth...
  27. Problem With A Mysql Join - Problem with a mysql join (2)
    Hello I am trying to write a script whereby I can pull an image out of one database table and
    display it in relation to its category_id in another table. I am using a my_sql join function that
    is joining the tables correctly, however it only shows the one same image from the top field of
    those combined rows on every single page. I need it display the image according to its category_id
    for that particular page. I am thinking I need to set variables to represent those specific rows but
    I'm not sure how to do that. Here is my code CODE { $result = mysql_que...
  28. Getting Php 5 To Work With Mysql - getting PHP 5 to work with MySQL (0)
    Just thought this would be of extreme help to those who are planning to migrate to php5 and still
    continue using MySQL same way as before:.... to get mysql work with the php 5 copy
    /dll/libmySQL.dll to the directory where php 5 resides and copy the /extensions/php_mysql.dll to the
    directory where php.exe resides.(if you can't find the two above files probably you are using an
    old release of php 5.you should check for latest at :http://snaps.php.net/) in additon uncomment
    extension line in php.ini and add the following code to a gnereal database file(dbcon.php) in m...
  29. Security Issue Writing Files - Security issue writing files (1)
    Hi, first, sorry about my english. i am a beginner with php and i have some question about writing
    files using php in a shared hosting. is a risk?, use database to store data is a better way? i just
    want make an interface (in php) that write the data in a .html extension file to show to everybody
    the html page and just the php interface is to the content manager. thanks in advance ...
  30. Php And Mysql Applications - (3)
    Ok I have started useing PHP and MySQL recently and I am wondering how I go about createing an
    application. I looked for tutorials and guids at w3schools.com but couldnt find what i was looking
    for. All I really need is a list of a few steps to take to get a general idea on were to start when
    makeing an application. I would appreciate any help you may have to offer....



Looking for blog, php, files, mysql

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for blog, php, files, mysql

*MORE FROM TRAP17.COM*
advertisement



Blog Using Php: Files Or Mysql?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
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