Page 1 of 1

URGENT HELP NEEDED! - simple PHP Guestbook save edit delete

Posted: Fri Dec 01, 2006 4:29 pm
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.

Posted: Fri Dec 01, 2006 4:38 pm
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

It has to be saved to a text file

Posted: Fri Dec 01, 2006 4:42 pm
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