PDA

View Full Version : Issues with IIS & Importing/Exporting text files for form data



dwnocturnal
31 Jul 2010, 02:00 PM
I'm relatively new to web design/development. I did a little bit back in the day, but mostly just html.

I've recently been given a task at work to employ a scrolling message board of hot items that are going on. I have no problem achieving this using the marquee tag for html. My issue is this:
Am I going to be the one updating this information all of the time? I doubt it, and no one else here has the knowledge (none whatsoever) to go in and edit the information that is scrolling on the page. To work on a way around this, I have implemented a link on this page to a page where a user can change the data that is scrolling and save it via a form. Herein lies my first problem:

I am trying to use a form with the <textarea> tag to allow them to input their data. This is fine, but I realized they would then have to copy and paste the previous data into this form if there were pieces that needed to remain...that won't do. I thought, ok, I'll just use php or asp to read the data from a text file and print it out in the text area...problem is, it never displays, it only ever displays the code and not the actual output. I have tried this several ways but cannot get it to work.

My next problem is then creating a function to save the data that they do edit in that form field directly to a file (actually the same file that it pulled the information from to overwrite it). Again I have tried several things here, but haven't been able to get it to work. Hopefully this is clear enough and I'll paste some examples below of what I have tried.

Ex 1 -

<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){
$data1 = $_POST['data'];
$file = "impact.txt";

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data1) or die("Couldn't write values to file!");

fclose($fp);
echo "Your changes were saved successfully!";

}
?>

<form name="form1" method="post" action="index2.php?saving=1">
<?PHP
$contents = file_get_contents($impact.txt);
?>
<textarea name="data" cols="100" rows="10">
<?=$contents?>
</textarea>
<br>
<input type="submit" value="Save">
</form>
<p>

Ex 2 - (This one doesn't even import the data from a text file :( )
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/>
<title>Test</title>
</head>

<body>
<form enctype="text/plain" method="POST" name="TestForm" action="impact.txt">
<p />
Input anything: <input type="text" name="anything" value="Default"/> <br />
<input type="submit" value="OK" name="submit"/>
</form>
<?php
if ($HTTP_POST_VARS['submit']=='OK') {
$fh = fopen("form_output.txt", 'w');
fwrite($fh, $HTTP_POST_VARS['anything']);
fclose($fh);
}
?>
</body>
</html>


My ultimate goal, if I can get this working, is to then just echo the text files on the scrolling message board so that they are updated by the users via the form. This way, the only thing they have to do is click a link, edit their text, click submit, and refresh their page.

Thanks in advance and please let me know if anyone needs clarification.