FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to code a simple blog using PHP





tingkagol
Hello.

After several years I've finally decided that I should learn how to code a simple blog using PHP. I just want the most basic things: REGISTER, POST, DISPLAY, ARCHIVE (and probably COMMENT).

Can anyone help me?

Thanks.
sonam
I am not sure you can code "SIMPLE" blog because you need lot of things. Maybe is better solution to use some finished free blog.

Sonam
joostvane
You can't learn to code a simple Blog. You can learn to code something simple. A blog asks a lot of coding. I recommend that you start by coding something like an address book first or something, thats what I did first.
rvec
a blog like that is simple, but if you don't know where to start you should probably start by making more simple stuff.

I'd recommend starting with a form where you submit data and put that in a mysql database (the blogging). Then learn how to do logins with sessions (other ways are possible but this is the best for a blog in most cases). If you can do those two things you can combine them and you already have your blog (almost).

When you got that you can start with sanitizing data and other security stuff. Then do the comments, and put the blog online (not before you learn how to use mysql_real_escape and escape html tags).
tingkagol
Thanks for the replies.

@joostvane: What's an address book? Or did you mean guest book? Can you show me / point me to the direction of tutorials? Thanks.

rvec wrote:
I'd recommend starting with a form where you submit data and put that in a mysql database (the blogging).

I especially want to start with this. I want to submit data to the database, and retreive it / display it on a page. Can you point me to a good tutorial? Thank you.
rvec
if you don't know where to start on this, I'd suggest starting with the basics of php.
You can find some tutorials here:
http://www.frihost.com/forums/vt-92218.html

After that it should be easy to make a form and use mysql connections.
Raidation
I can help you.
Basically, first, you make a basic template for a blog post. This should be obvious. then, where the content is supposed to go, you insert: <?php $content ?>

Now, in your body, write where the blog posts are supposed to be:
Code:
<?php
$array=Array("Post1","Post2","Post3");
for(i=0;i<=$numberofposts-1;i+=1) {
$content=$array[i];
include("blogpostfile.php");
}
?>
rvec
rofl
that's a bad way to do that, and you should use code tags when posting code.

I'd suggest using themes only when you know how to work with sessions, know some basics about design (not graphical but architectural) and have seen how other do it. The way radiation handles themes they have minimum added value.
babarus
http://www.w3schools.com/ is a good tutorial .
If you want to make a blog is no so dificult using a open-source code but to code a blog is a hard work.
iGniSz
I recommend you start your PHP career by picking a framework and sticking with it. The curve will be steep at first but once you start to know what your doing you will be developing faster then your DIY peers. Also you will be marinated in well thought out code, which is better then being stuck in your own ideas (that may or may not be good ways to do it!).

I would recommend codeigniter, They even have a start your own blog video tutorial: http://codeigniter.com/tutorials/watch/blog/

I say, watch it, follow it, slowly build on that. Igniter allows you to sidestep it pretty easily so if you have a better idea on how to do it... you can actually do it that way!

Happy coding,
Jillis
rvec
iGniSz wrote:
I recommend you start your PHP career by picking a framework and sticking with it. The curve will be steep at first but once you start to know what your doing you will be developing faster then your DIY peers. Also you will be marinated in well thought out code, which is better then being stuck in your own ideas (that may or may not be good ways to do it!).

I would recommend codeigniter, They even have a start your own blog video tutorial: http://codeigniter.com/tutorials/watch/blog/

I say, watch it, follow it, slowly build on that. Igniter allows you to sidestep it pretty easily so if you have a better idea on how to do it... you can actually do it that way!

Happy coding,
Jillis
I don't think it'd be a good idea to start with frameworks if you can't even make a blog by yourself. If making a blog is hard you're missing at least some of the basics in PHP, and with a framework you'll need those basics to use the framework to its full extend.
iGniSz
Hej rvec!

Well depending on your goal .. that would be a better idea, but the OP's question is how to build a simple blog. Using/learning a framework is the best way to do this in a smallish amount of time.

Also doing this circumvents the need to know all kinds of small details because the framework creators will already have thought a lot about them. A lot of those details are not really insightfull anyhow. Even then you will have to code a lot of stupid methods for things like CRUD and authentication.. BTW coding that stuff will teach the OP all the basic PHP control flow and syntax he needs to do more complex stuff / self-styled stuff.

More importantly, this will enable the OP to accomplish stuff fairly quickly. This will keep the most precious commodity in the early learning phase in supply. Im talking about willpower here, because it's really needed to do anything in programming..
rvec
you really think someone who doesn't know how to do a SELECT, make an array or make a simple loop would need less time to understand a full framework than to understand those simple things and create a blog?

If you use a framework you also have to understand design principles (can't use a standard framework if you don't know how MVC or singleton works), and there aren't a lot of frameworks which don't use objects (which are hard to understand if you never heard of them).
iGniSz
Quote:
you really think someone who doesn't know how to do a SELECT, make an array or make a simple loop would need less time to understand a full framework than to understand those simple things and create a blog?


This is not needed. Just follow along with the tutorials. And even then almost nobody understands a complete (mature) framework. You don't need to.

Quote:
If you use a framework you also have to understand design principles


No, you just have to work in the chosen architecture. Designing a framework required a solid knowledge of design principles.

Quote:
(can't use a standard framework if you don't know how MVC or singleton works)

?? Check out this tutorial for codeigniter [http://www.phpandstuff.com/articles/codeigniter-doctrine-from-scratch-day-1-install-and-setup]

It explains MVC .. well enough to make it workable at first. Using this tutorial the OP could have a simple blog up by the end of the week!

IE it says "Controllers are called by CodeIgniter on every page load." What more do you need to know how to work with MVC??
<?php
// system/application/controllers/hello.php
class Hello extends Controller {

function world() {
echo "Hello CodeIgniter!";
}

}

do you need to understand what a class exactly is? No.. you don't .. you just need to know where to put code for a given url.

You don't need a SELECT if you use Doctrine...

Don't make this harder then it needs to be .. Using and sticking with a framework and learning its ins and outs is by far the best way to proceed for the OP.
rvec
Yeah I guess you could copy paste everything from the tutorial, and be happy when you see something appear in the browser. But to really use the framework you should know a bit more. If you don't know how objects work you could of course just put everything in the right functions and never know what a class means, but in that case you won't be able to use magic methods, class-scope variables, extend other classes (other than the default) and you'd probably write procedural style code inside the functions.

Quote:
And even then almost nobody understands a complete (mature) framework. You don't need to.

Eehm, if you're still talking about the PHP frameworks then I have to disagree. Codeigniter is fairly simple for example and a good programmer should really take his time to understand the full framework before starting to do serious stuff with it. Finding out that the codigniter guys already solved a problem you've been wasting days on is really a bad feeling ... Embarassed
iGniSz
Yes doing this will allow you to gradually get to know PHP. At first it is like you described, but after a week some patterns should start to emerge. Research these patterns would lead to the kind of knowledge you are describing.

Listen to what you are saying.. if you want to make a simple blog, you have to study design patterns, SQL syntax, PHP syntax, PHP semantics and a lot of webserver/browser specific stuff. Then you will have to learn HTML syntax/semantics and CSS syntax/semantics oh jeah and Javascript syntax / semantics, some *nix system administration thrown in, Apache administration..

Each could easily take you 3 months. I remember having Java in college and it was a 2/3 month course after which I knew the basics and not much more.

What i'm saying is.. start with a good framework. Don't worry to much about learning before you start.. just start and learn on the go. This way you'll keep motivation up because you are actually doing (and succeeding) at something. It can take years to get good at programming.

Codeigniter is especially suited for this, as most components can be used in isolation or are easily replaced by your own code, so when your knowledge level rises you can start building your own codes.

Also, rvec, lookup Nirvana fallacy, because "Yeah I guess you could copy paste everything from the tutorial, and be happy when you see something appear in the browser" is a nirvana fallacy. I'm not saying "blindly copy paste stuff".. because you will never get anywhere with such an attitude.

Think of the framework + tutorial as you elementary school maths book! It has a lot of structure already in there to get you started in the good direction, you can discard this structure when you het better.

And in the end, if you push through .. you will have some very valuable experience on your CV. Namely the framework you know, now you slot into any team that works with that framework.
rvec
Quote:
Listen to what you are saying.. if you want to make a simple blog, you have to study design patterns, SQL syntax, PHP syntax, PHP semantics and a lot of webserver/browser specific stuff. Then you will have to learn HTML syntax/semantics and CSS syntax/semantics oh jeah and Javascript syntax / semantics, some *nix system administration thrown in, Apache administration..

SQL and PHP is needed for a simple blog, although you need less PHP than you'd need to work with codeigniter. Because a simple blog doesn't need any functions, objects or separated MVC.

You don't need any webserver/browser/javascript/*nix/apache. Or at least not more than you'd need for working with codeigniter. You'd need exactly as much html and css as with codeigniter, but I think we can agree anyone who starts with php should at least know the basics of html and css.

Just to show you what I mean, because I have the feeling we don't both have the same idea about what a simple blog is.
one frontpage with all the posts (index.php)
one login page and logout (login.php)
one posting page (post.php) to be accessed when you're logged in only
one table with posts
one table with users
iGniSz
I agree with your breakdown of a simple blog. And also I would like to point out that I think your approach is very valid and it really depends on the OP. How much energy/time is available and what the OP wants to do afterwards..

So I would like to shortcircuit this discussion, because it's not about the most best way to do things, I don't even believe there is a single best way. It depends very much on the OP.. I just wanted to give my opinion and got dragged into this discusion.. I feel this is the best way to go about the OP's question given his background, and you think yours is.. that's fine! Because it's the OP who wants to make a blog.. he/she needs to decide Very Happy

I agree that you need to know some basic HTML and CSS to make a simple blog, im just saying it's really doable to start with 0 knowledge, and go upto a bit during the development. Imho .. this is possible by selecting a good framework that allows you to ignore certain areas of the knowledge domain whilst focussing on others. Doing this iteratively gives you all the knowledge you need..
rvec
iGniSz wrote:
I agree with your breakdown of a simple blog. And also I would like to point out that I think your approach is very valid and it really depends on the OP. How much energy/time is available and what the OP wants to do afterwards..
True


iGniSz wrote:

So I would like to shortcircuit this discussion, because it's not about the most best way to do things, I don't even believe there is a single best way. It depends very much on the OP.. I just wanted to give my opinion and got dragged into this discusion.. I feel this is the best way to go about the OP's question given his background, and you think yours is.. that's fine! Because it's the OP who wants to make a blog.. he/she needs to decide Very Happy
Yeah true again.


iGniSz wrote:

I agree that you need to know some basic HTML and CSS to make a simple blog, im just saying it's really doable to start with 0 knowledge, and go upto a bit during the development. Imho .. this is possible by selecting a good framework that allows you to ignore certain areas of the knowledge domain whilst focussing on others. Doing this iteratively gives you all the knowledge you need..

The only point where I disagree, is that I don't think you'll get all the knowledge when starting with a framework.
Maybe we need to find two people who want to start with PHP and just let them try, I have a feeling we can continue this discussion for a while Razz
raver
Smile This thread is funny Razz
Anyway, no one thought of asking one simple question to the thread starter.
WHY do you want to achieve this?
Is it so you can learn how to program?
In that case forget about a framework. I thought 2 years php and mysql to people who had no clue about programming, and diving heads on into a framework is not the correct way of approaching this.
Do you just want a blog in which to write for your friends?
Then get wordpress from http://www.wordpress.org and use that. It is incredibly simple to use.

IF you want to learn the programming files, then you need to study the following concepts
1) PHP variables.
2) PHP arrays.
4) PHP conditional structures.
5) PHP repetitive structures.
6) PHP Functions
7) MySQL queries SELECT
Cool MySQL queries UPDATE
9) MySQL queries DELETE
10) MySQL queries INSERT
11) PHP mysql functions
I wrote them like that so you can just google each and get all the info you need to build your own blog Smile
Of course, many other things will be needed to improve afterwards, but if you learn this, you will be on your way Smile
zacky
sonam wrote:
I am not sure you can code "SIMPLE" blog because you need lot of things. Maybe is better solution to use some finished free blog.

Sonam


yeah sonam was totally right.

There's a lot of bunch of things to do before you come up to the blog sites disregarded what ever

blog site it is. I'm still a newbie in PHP and MySQL because i feel that im not totally capable to the

a site for top big huge companies even i studying it for about a year.
rvec
Quote:
I'm still a newbie in PHP and MySQL because i feel that im not totally capable to the a site for top big huge companies even i studying it for about a year.

Any programmer who would say he/she would be able to make a big company website alone wouldn't be up to the task.

Quote:
WHY do you want to achieve this?

Quote:
After several years I've finally decided that I should learn how to code a simple blog using PHP
guissmo
rvec wrote:
if you don't know where to start on this, I'd suggest starting with the basics of php.
You can find some tutorials here:
http://www.frihost.com/forums/vt-92218.html

After that it should be easy to make a form and use mysql connections.


Wow thanks, I found this very helpful.
Related topics
[tutor] How to protect images without htaccess using PHP
Open, Write to and Close a txt file using php
I am trying to build a contact form using php and flash
Communicating between web pages
Checking server status (ports) using PHP
Using PHP "OR" Logical Operator
Using PHP code from a Database
Access Java 1.6 Web service using php client
Email Using PHP
"Drop Down List Box" Using PHP and MySql
Can I add tasks to Windows Scheduled Tasks - Using PHP?
MySQL Database Backup Using PHP
Fetch Alexa Rank of website using PHP function easily
Help displaying pdfs using PHP
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.