PHP blog using forms

Soldato
Joined
1 Dec 2004
Posts
23,076
Location
S.Wales
OK, i have a website made up of XHTML and CSS, what i want is to be able to post news and info on one of the pages using PHP, but i dont want to have to keep editing the html, i want to create a form on a seperate page when i can enter the news and info, when i push submit i want it to submit the form but post the main message field into one of the XHTML Pages (news) in a layed out fashion in the body div..Similar to below:



---------Todays Date, Current Time--------------------------
NEWS NEWSNEWSNEWSNEWSNEWSNEWSNEWSNEWSNEWSNEWS

------------------------------------------------------------

Can anybody shed any light on the best way to do this?

Any tutorials will be great!
 
Could it not be done by using php and a txt file? i dont need it to be fancy, i just want a bog standard blog.
 
jdickerson said:
Nahhhhh.....

Have this on an admin page*:

Code:
<form method="POST" action="form.php" name="news">
	<font face="Tahoma" size="2">new:</font>
	<br>
	<textarea name="c" style="width: 350px; height: 100px"></textarea>
	<br>
	<input type="submit" value="Add" name="submit">
</form>
<br>
<br>
<font face="Tahoma" size="2">news:</font><br>
<?php include("file.txt"); ?>

Create a file called form.php:
Code:
<?php
$datfile = "file.txt";
$max = 250;
$num = 1000;
$todayis = date("l, F j, Y, g:i a");
$comfile = file($datfile);
if ($c != "") {
if (strlen($c) < $max) {
$fd = fopen ($datfile, "w");
$c = stripslashes($c);

fwrite ($fd, "<p><table><tr><td>$todayis</td></tr><tr><td>$c</td></tr></table></p>\n");
for ($i = 0; $i < $num; $i++) {
fwrite ($fd, $comfile[$i]);
}
}
fclose($fd);
}
Header("Location: ADMIN PAGE URL");
?>


Create a file called file.txt, chmod it to give writing permissions and then just call the file with:
Code:
<?php include("file.txt"); ?>
...where you want the 'news' to go. The html in the text will be read and treated as such.

* SECURE it! You'll want to prevent using most symbols I imagine using str replace (e.g. using above could include an iframe to another site, applets etc...) so once again SECURE IT! Change tables --> Div etc..

EDIT - I also can't be bothered correctly writing the HTML as I assumed you'd have your own site stylesheets etc...


Yep i have my own style sheet etc. Im going to have ago at both ways to see which gives best results, i have already found a tutorial on the web and mocked up my own version of the php/sql one but im yet to test it and iron out the bugs.

With this txt file one. just a few questions for you...


1) Could you explain abit more when you mean "Secure it" im abit confuzzled?

2) "Create a file called file.txt, chmod it to give writing permissions" - Whats chmod, iv never run into this phrase before?
 
Back
Top Bottom