Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 07-05-2008, 06:39 PM   #11
In Runtime
Join Date: Dec 2007
Posts: 195
Default Re: Taught myself PHP

Originally Posted by ssc456 View Post
i know html id say quiet fluently javascript im still edgy aboutbut heres the site i need the guestbook for,


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 Code:
//connect to the DB
include 'opendb.php';

$action $_GET['action'];
$action == 'insert')
//get the message variable from POST
//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);
"Item has been inserted into the Guestbook.";
//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.
$user $row['user'];
$datetime $row['datetime'];
$message $row['message'];
"<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;'>
//display a form to submit a new message
       <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;'>

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.

colorblindjimbo is offline   Reply With Quote
Old 07-06-2008, 10:58 AM   #12
Fully Optimized
ssc456's Avatar
Join Date: Jan 2007
Posts: 4,279
Send a message via MSN to ssc456
Default Re: Taught myself PHP

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

He who has never failed has never attempted anything worth succeeding at.

Dont Eat Animals, Its Not Good For Them And They Dont Like It!
ssc456 is offline   Reply With Quote
Old 07-20-2008, 04:48 PM   #13
Site Team
David Lindon's Avatar
Join Date: Dec 2002
Posts: 15,233
Default Re: Taught myself PHP

Nice site, I like the layout

[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 04:20 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0