CG_dude Posted February 5, 2009 Share Posted February 5, 2009 Hi all, Please kindly a little direction. I'm new to PHP, but I have built a site that is just about to complete for my work. Been a long road, but a learning road with a lot of reading and it's been good, However, I am having an issue. My site consists of tracking job times, and if one of the times misses it's SLA, then I need to beable to add a comment in a text field and have it stay there until I clear it. The goodies, I am running PHP 4 and on a unix webserver, the script I'm running is not giving me what I want, and I need the text that I enter to be on the same page. I've tried Iframes using html but to no avail, here is my code <TD> <?php $myFile = "/users/apache/hpws/apache/htdocs/pa_box_settle_com.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); echo "changes have been submited"; fwrite($fh, $newcontent); fclose($fh); ?> </TD> I want to be able to enter text and have it write to the pa_box_settle_com.txt and then echo it back to the webpage? Is this possible? Link to comment https://forums.phpfreaks.com/topic/143893-solved-help-with-user-data-from-text-field/ Share on other sites More sharing options...
CG_dude Posted February 5, 2009 Author Share Posted February 5, 2009 it's only echoing the text "changes have been submited" and does not give me the option to open the txt file and enter text in a text field Link to comment https://forums.phpfreaks.com/topic/143893-solved-help-with-user-data-from-text-field/#findComment-755058 Share on other sites More sharing options...
CG_dude Posted February 5, 2009 Author Share Posted February 5, 2009 Maybe there is a better way to do it, maybe like using a form, by entering data in the form, hitting the submit button and having it write to a text file,then echo the text file in the same table area. I did try Iframes but I may have missed something, any clues ? This is the code I tried <TD><IFRAME src="pa_comments.html?story={sid}" frameBorder=1 width="170%" height=45> </IFRAME> <FORM action=pa_comments.html method=post> <INPUT name=Comment> <INPUT type=submit value="Submit Query"> </FORM> </TD> Again, I'm able to write in the text field, but the text is not written to the pa_comments.html file and does not echo back the results. Link to comment https://forums.phpfreaks.com/topic/143893-solved-help-with-user-data-from-text-field/#findComment-755067 Share on other sites More sharing options...
CG_dude Posted February 5, 2009 Author Share Posted February 5, 2009 Any suggestions, to how I can have a user enter data from a text field and have that data write to a text file and then have the file contents be echoed to the same page ? Maybe JAVA ? Link to comment https://forums.phpfreaks.com/topic/143893-solved-help-with-user-data-from-text-field/#findComment-755449 Share on other sites More sharing options...
CG_dude Posted February 6, 2009 Author Share Posted February 6, 2009 Solved it myself, changed the code up a bit. You have to create the text file on the server first, then put in this code. Don't need a data base <?php $filename="textfile.txt"; //sets file to edit $readfh = fopen($filename, "r"); //File handle for $filename $contents = fread($readfh, filesize($filename)); //Reads file, through handle $readfh. ?> <html> <head> <title>File Editor Test</title> </head> <body> <h1>File Editor Test</h1> <?php if(isset($_POST['submit'])) { //if submit was pressed $writefh = fopen($filename, "w+"); //File handle for $filename if(get_magic_quotes_gpc()){ $newcontents=stripslashes($_POST['editcontents']); } //strips unneeded backspaces by magicquotes else{ $newcontents = $_POST['editcontents']; } //NEXT 3 LINES ARE THE PROBLEM SPOT: fwrite($writefh, $newcontents, strlen($newcontents)); //Saves changes rewind($readfh); //resets cursor in file $contents = fread($readfh, filesize($filename)); //Updates $contents fclose($writefh); } ?> <form method="post" action="<? echo($PHP_SELF); ?>"> <textarea name="editcontents" style="width:170px; height:70px;"><? echo shell_exec('cat textfile.txt');?></textarea> <br /> <input type="submit" name="submit" value="Comment" /> <?php fclose($readfh); ?> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/143893-solved-help-with-user-data-from-text-field/#findComment-755628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.