URGENT HELP NEEDED! - simple PHP Guestbook save edit delete

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maxvee8
Forum Newbie
Posts: 3
Joined: Fri Dec 01, 2006 4:15 pm
Location: United Kingdomator

URGENT HELP NEEDED! - simple PHP Guestbook save edit delete

Post by maxvee8 »

hi ive not been coding php for very long and iam stuck, im making a php guest book that saves entries to a text file i have made it so that i can add entries to the text file and it dispalys each one on the screen the problem iam having is with the adminsection.

the code i have at the minute makes it so that i can retrive the entries and diplay each one in a text field this will allow me to edit any comments then i will beable to save the changes or just delete an enry altogether

i need to know how to delete an etry altogether from the text file and save the edited comments

the code for my admin section at the minute is

Code: Select all

//admin user name and admin password
$adminUserName = 'admin';
$adminPass = 'password';
//form elements for admin login
$adminUser = $_POST['user'];
$adminPass = $_POST['pass'];
//check to see if passwords match
if ($adminUser == $adminUserName && $adminPass == $adminPass){
echo ("You are now logged in as admin");

$txtFile = "g.txt";
$filepointer = fopen($txtFile, "a+")
or die("txt file missing");
$data = fread($filepointer, filesize($txtFile));


$a_post=explode(";",$data);
$number=count($a_post)-1;

print("<div id='entry'>");
for ($i=($number-1);$i>=0;$i--){
	$a_element=explode("|",$a_post[$i]);
	print ("Post No: " . ($i+1) . " on the " . $a_element[0] . "<br/>" . "Posted by " ."<input type='text' value='". $a_element[1] . "'> they said:<br/><em>" ."<input type='text' value='". $a_element[3] . "'></em><br/><br/>" . $a_element[1] . "'s url: ".$a_element[2] . "<hr/>");
	print("<div id='submitButton'>");
	print("<input name='delete' type='button' value='Delete'/>");
	print("<input name='save' type='button' value='Save'/>");
	print ("</div>");
	
}
print("</div>");

}else{
die ("Your username/password is not correct");
}
i need to keep it as simple as possible thanks to any one who can help me also any one reading this i need to know about bad word filter, check all form elements have something in, and if possible let people reply to peoples messages that are posted and any other extrtas that you can think of that a guest book might need.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Sorry to digress from your question, but have you considered using a database like mysql or sqlite? That, in my opinion would be MUCH easier than trying to fiddle with so many file and string manipulation... and you wouldn't have to worry about issues like file locking
maxvee8
Forum Newbie
Posts: 3
Joined: Fri Dec 01, 2006 4:15 pm
Location: United Kingdomator

It has to be saved to a text file

Post by maxvee8 »

hi yeah it would be nice with mysql but it has to be saved to a text file at the minute maybe in the future ill do database
Post Reply