Member Avatar for bthaxor

hey everyone,

i've been using a wordpress blog for a while now, and i recently decided i'm tired of the hassle of having to manage all the plugins, spam comments and updates. i don't know a lot about php either, however i am a web designer by hobby: so i decided to create a simple static html layout, and then have just one page as my blog, which i would regularly update.

herein lies my problem: i dont want to have to reupload the blog.html page manually every single time i want to post a new entry (and i actually blog quite a lot), so i would like some external script (sort of like the wordpress writer) to automatically insert new blog posts. i don't know if i've made myself clear enough, so i'll use an example - this is current code from my page which will represent every blog post:

<div class="post">
	<div class="post_title"><h2>title of blog post</h2></div>
	<div class="post_date">April 16th, 2009</a></div>
	<div class="post_body">
		<p>blog entry goes here</p>
	</div>
</div>

so all i'm asking for is a simple php file with two fields: title and post, which writes to my html page in the format above either via another php file or using a mysql database. also, you may have noticed there is also a div for the date the entry was posted - i would like this to be stored somehow too.

hopefully, the code would be generic enough to use with future websites too... :)

on a side note, it'd be great if someone could also tell me how to create 'pages' - so let's say if there are more than 10 posts and i create a news2.html page, it would flow from one page to the other... but that's just an added bonus :)

all help would be appreciated... i don't know much about php, but i hope this is as simple as i think it should be :P

-bthaxor

I would suggest using mysql databases and the following is an example mysql query:

mysql_query('INSERT INTO `table` SET `title`="'.mysql_real_escape_string(stripslashes($_POST['title'])).'" `date`="'.mysql_real_escape_string(stripslashes($_POST['title'])).'" `body`="'.mysql_real_escape_string(stripslashes($_POST['title'])).'"')

Then to place the contents into a page use the following:

$result = mysql_query('INSERT INTO `table` SET `title`="'.mysql_real_escape_string(stripslashes($_POST['title'])).'" `date`="'.mysql_real_escape_string(stripslashes($_POST['title'])).'" `body`="'.mysql_real_escape_string(stripslashes($_POST['title'])).'"')
while($row=mysql_fetch_array($result)) {
echo '<div class="post">
	<div class="post_title"><h2>'.$row['title'].'</h2></div>
	<div class="post_date">'.$row['date'].'</a></div>
	<div class="post_body">
		<p>'.$row['body'].'</p>
	</div>
</div>';
    }

Hope that helps.

all i'm asking for is a simple php file with two fields: title and post

never say "simple" until you know how to do it. nothing is ever so simple:

You will need to store all the blog posts which consists of all the information such as title, date and body into the a database. This database is most likely to be MySQL. www.mysql.com

having planned the database tables, you need to know to to query to tables to retrive/store information. PHP provides some built in functions so look up mysql_query() in www.php.net.

but you will still need to learn the SQL (structure query langauge) that commands the database to do stuff. the php functions merely let you connect to the database, it doesn't help you get or set information. for SQL, read the documentation in www.mysql.com search for SELECT and INSERT clause.

If you don't have the basics to start with, this is not simple at all. But googling for these keywords should get you quite far.

Good luck! =)

Member Avatar for bthaxor

thank you for everyone's help. using the advice given to me here and help from a php-dedicated irc channel, i managed to get everything set up perfectly :)

a simple concept wasn't so simple in practice... :P

i intend to soon learn php since it seems very useful...

thank you all again.

There are plenty of ready-made Blog scripts available, some free. These will be typically many thousands of lines of php/css/templates, giving you some idea of the complexity of your project. The best of them will be significanty more secure than a DIY job, which is a real issue with php.

Try searching eg. the php section of hotscripts.com (hasten to add, there are many other good script sites).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.