Hi, I have just started using PHP and have been looking for/trying to write a simple script that will allow me to add news to the top of a page of HTML, i.e. like a weblog.
All I want is one page where I can submit a topic header and a main body for a message, possibly with the time and date, and clicking a button will add this information into the HTML of the frontpage. Of course, this means that the HTML file will be getting larger and larger as news is added but I can live with that!
If anyone knows of a way of doing this, or if I am barking completely up the wrong tree and there is a better way of doing it, I would be most appreciative to hear about it!
Thanks.
Newbie Q
Moderator: General Moderators
As a newbie myself, i cannot give you the full details, but I know sorta how to do this.
On your HTML page you will want to put the following at the top:
<?php
require("weblog.php")
?>
Now, after doing that, you need to create weblog.php and create weblog.html.
weblog.html should be a form that changes the content of weblog.php
I can't give you the exact coding, but I recommend you read "PHP and MySQL Web Development" by Laura Wellington. The book is purple and white and published by SAMS. It took me a month to read and from there I have learn much. Of course, actuall practice is what I still require to become the expert I strive to be, but this book is a good start. In it, it shows how to set up a form and file for just what I am suggesting. I just don't have the book on hand at the moment.
Good luck.
On your HTML page you will want to put the following at the top:
<?php
require("weblog.php")
?>
Now, after doing that, you need to create weblog.php and create weblog.html.
weblog.html should be a form that changes the content of weblog.php
I can't give you the exact coding, but I recommend you read "PHP and MySQL Web Development" by Laura Wellington. The book is purple and white and published by SAMS. It took me a month to read and from there I have learn much. Of course, actuall practice is what I still require to become the expert I strive to be, but this book is a good start. In it, it shows how to set up a form and file for just what I am suggesting. I just don't have the book on hand at the moment.
Good luck.
Here's a rough sketch:
Database: create a table with auto-increment int column for a unique article ID; varchar col for title; text col for body. Could also add another int-type column for a timestamp.
Php retrieve articles function: simple SELECT query (see mysql.com for manual if you need more info). You can display all by SELECT * .. etc, or you could LIMIT the query to a certain number of articles, or use timestamps to show all after a certain date.
Define vars for $title and $body and return them as an array ($output['title'] = $title; $output['body'] = $body; finish with return $output;).
Creat an html template to format the $output - I like to use Dreamweaver (yes I know..!). No head/body tags because you'll use: include("path_to/template.html") to add the template to the main page. In the template, embed some php code <?php echo $output['title']; ?> and <?php echo $output['body']; ?> wherever you want title and body to go.
Php submission form: Dreamweaver makes it easy to create an html form template. Name the form fields "title" and "body". Form method = POST, point the action at your form processor. You can use include("path_to/form.html") to add the form to a php page (cut out all the head/body tags just leaving the form stuff) or use the html file as is.
You can also use this form to edit articles but I'll leave that for now.
Php form processor function: an INSERT query to stick $_POST['title'] and $_POST['body'] in the database. Use the time() function if you also want to record a timestamp.
It all looks a bit daunting at first but it's actually fairly simple once you get familiar with the php language. Adding/retrieving info from a database is the meat and bones of dynamic websites using php so it's a good thing to start on.
Working with html templates is a good method to learn - keeps the code and the formatting separate.
Good luck!
Database: create a table with auto-increment int column for a unique article ID; varchar col for title; text col for body. Could also add another int-type column for a timestamp.
Php retrieve articles function: simple SELECT query (see mysql.com for manual if you need more info). You can display all by SELECT * .. etc, or you could LIMIT the query to a certain number of articles, or use timestamps to show all after a certain date.
Define vars for $title and $body and return them as an array ($output['title'] = $title; $output['body'] = $body; finish with return $output;).
Creat an html template to format the $output - I like to use Dreamweaver (yes I know..!). No head/body tags because you'll use: include("path_to/template.html") to add the template to the main page. In the template, embed some php code <?php echo $output['title']; ?> and <?php echo $output['body']; ?> wherever you want title and body to go.
Php submission form: Dreamweaver makes it easy to create an html form template. Name the form fields "title" and "body". Form method = POST, point the action at your form processor. You can use include("path_to/form.html") to add the form to a php page (cut out all the head/body tags just leaving the form stuff) or use the html file as is.
You can also use this form to edit articles but I'll leave that for now.
Php form processor function: an INSERT query to stick $_POST['title'] and $_POST['body'] in the database. Use the time() function if you also want to record a timestamp.
It all looks a bit daunting at first but it's actually fairly simple once you get familiar with the php language. Adding/retrieving info from a database is the meat and bones of dynamic websites using php so it's a good thing to start on.
Working with html templates is a good method to learn - keeps the code and the formatting separate.
Good luck!