Jump to content

[SOLVED] Help with user data from text field


CG_dude

Recommended Posts

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?

 

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.

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.