Schlo_50 Posted May 18, 2007 Share Posted May 18, 2007 I have a page whereby a text area is shown, and the initial value of it uses php to display the contents of the .txt file so that a user to update the paragraph of text shown and click submit to overwrite the .txt file with new information. The problem is i have no idea how to code it so that i can make the .txt file be over written. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #6191c2; } --> </style> <SCRIPT language="Javascript"> function selectit(input){ document.formname.news.value+=input } </SCRIPT> </head> <body> <label> <p><span class="rotary"><strong>Text Editor </strong></span><br /> <br /> //This part here is where i have tried to make an over write. <?php if ($_POST['submit'] == "Submit") { $file_name = "home.txt"; $open_file = fopen($file_name, "w"); $file_contents= $_POST['title'] . '|' . $_POST['news'] ."\n"; fwrite($open_file, $file_contents); fclose($open_file); echo "Form data successfully written to file"; } ?> </p> <p> Title: <label> <input type="text" name="title" /> </label> </p> <p> <?php $prnt = "<img border=\"0\" src=\"images/bold.jpg\" width=\"25\" height=\"25\" alt=\"Bold\" onClick=\"selectit('<b>Text Here</b>')\"> "; $prnt .= "<img border=\"0\" src=\"images/underline.jpg\" width=\"25\" height=\"25\" alt=\"Underline\" onClick=\"selectit('<u>Text Here</u>')\"> "; $prnt .= "<img border=\"0\" src=\"images/link.jpg\" width=\"25\" height=\"25\" alt=\"Hyperlink\" onClick=\"selectit('<url=http://www.site.com>Site Name</url>')\"> "; ?> <?php echo("$prnt"); ?> <br /> </p> <form name="formname"> <p> <textarea name="news" cols="85" rows="15" id="news"> <?php $file = file("home.txt"); foreach($file as $key => $val){ $data[$key] = explode("|", $val); $text = $data[$key][0]; print( $text ); } ?> </textarea> </p> <p> <label> <input type="submit" name="submit" value="Submit" /> </label> </p> </form> </label> </body> </html> Please Help!! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51958-editing-and-overwritting-data-in-txt-file/ Share on other sites More sharing options...
neel_basu Posted May 18, 2007 Share Posted May 18, 2007 Have you tested or tried anything yourself still now ?? If yes then whats teh Error message you got ?? Quote Link to comment https://forums.phpfreaks.com/topic/51958-editing-and-overwritting-data-in-txt-file/#findComment-256116 Share on other sites More sharing options...
phast1 Posted May 18, 2007 Share Posted May 18, 2007 From a quick look at your code, it seems like it should work.. Is there an error being displayed when you try to run it?? Quote Link to comment https://forums.phpfreaks.com/topic/51958-editing-and-overwritting-data-in-txt-file/#findComment-256117 Share on other sites More sharing options...
Schlo_50 Posted May 20, 2007 Author Share Posted May 20, 2007 There is not error message, thats the thing. It just doesn't actually edit and update the .txt file which is echoed in the text area. Quote Link to comment https://forums.phpfreaks.com/topic/51958-editing-and-overwritting-data-in-txt-file/#findComment-257897 Share on other sites More sharing options...
dj-kenpo Posted May 21, 2007 Share Posted May 21, 2007 are your permissions set for read+write in whatever folder you're storing the txt in? Quote Link to comment https://forums.phpfreaks.com/topic/51958-editing-and-overwritting-data-in-txt-file/#findComment-257932 Share on other sites More sharing options...
Schlo_50 Posted May 21, 2007 Author Share Posted May 21, 2007 I don't know, but i am testing the files locally so would that matter? If so how do i change this? Quote Link to comment https://forums.phpfreaks.com/topic/51958-editing-and-overwritting-data-in-txt-file/#findComment-258020 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.