Taught myself PHP

i know html id say quiet fluently javascript im still edgy aboutbut heres the site i need the guestbook for,

http://ben-jordan.co.uk/

i really hus want a way of saying,

click.submit write="text.comments" to post.txt

and on the next page, read="post.txt" and enter the comments written earlier.

ive been looking abit at reading and writing .txt file in php but its still alittle above me at the moment
You'de want to use a database, not a .txt file. This way you can organize the information much easier.

I'm just pounding out some code here, it isn't tested by here you go:
PHP:
//connect to the DB
include 'opendb.php';

$action = $_GET['action'];
if($action == 'insert')
{
   //get the message variable from POST
   $message=$_POST['message'];
   //save formatting
   $message = nl2br("$message");
  //escape problematic characters
  $message = mysql_real_escape_string($message);
  //get user variable from POST
  $user = $_POST['user'];
  //perform the SQL query
  $sql = "INSERT INTO table_name datetime=NOW(), message=$message, user=$user";
   $result = mysql_query($sql);
   echo "Item has been inserted into the Guestbook.";
}
else
{
//query the database for all entries in the guestbook in chronological order, from most recent to oldest.
$sql = "SELECT * FROM table_name ORDER BY datetime DESC";
$result = mysql_query($sql);
//display a table with all the information for each entry until all entries have been displayed. If you want to add a Page(s) system, you can do a counter here.
while($row=mysql_fetch_array($result))
   {
   $user = $row['user'];
   $datetime = $row['datetime'];
   $message = $row['message'];
   echo "<table><tr><th>Time Inserted:$datetime<th>Author:$user
   <tr><th colspan=2>Message:<br>
   <p style='background-color: #ADFF2F; padding: 15px; border-style: double;'>$message</p>
   </table>";
   //display a form to submit a new message
   echo"
       <table><form action='pagename.php?action=insert' METHOD=POST>
       <tr><th colspan=3>Add to the Guest Book
      <tr><td>Name:<td><input type=TEXT name='name'>
      <tr><th colspan=2>Message:
      <tr><td colspan=2><textarea name='message' cols=40 rows=9></textarea>
     <tr><td colspan=2><input type=SUBMIT value='Add to GuestBook' style='float: right;'>
      </form>
      </table>
       ";
   }

}
This is a multi_purpose website, meaning you only need 1 page, there is not second page. You will just need to change the ACTION='pagename.php?action=insert' to be the page's name instead of pagename.php.

This uses a mysql database with the name of table_name (change it to what you like), with the fields of datetime(field type is datetime), user(varchar(50)), and message(varchar(500)).
You will also need to create a file named opendb.php, that initiates the connection to the MySQL server.
 
ok cool ill get back to you monday probably im busy decorating all this weekend so dont have much time to go playing at mo,

but thanks def worth some +1 :)
 
Back
Top Bottom