My goal here was to write a bit of PHP and using forms to give a good freind of mine backend access to his site without using sql ( Since he is running Vbulletin and doesn’t need any more database files to mess with or backup ) I though something simple as adding text files into a directory where he can go in and fill in the blanks into a form and once submitted have it appear in my predesigned layout on a new page.
I have 2 pages ( still in test phase )
pageedit.php ( which will eventually have a password lock ) and pageview.php
The only way I could get it to work right every time was to get it to post to pageview.php
and when you left that page and returned to page edit everything was fine. No errors no
problems until you goto pageview.php directly and that automatically erases all the content
from the text files thus causing my problem. Can someone point me in the right direction on how to fix this. Maybe a if statement or a way I can make pageview tell I have not
been redirected and fail ? Any suggestions would be greatly appreciated…
Content of pageedit.php
<?php
$theData1 = file_get_contents('datafile1.txt', true);
$theData2 = file_get_contents('datafile2.txt', true);
$theData3 = file_get_contents('datafile3.txt', true);
?>
<form method="POST" action="pageview.php">
<p>Enter Persons Name here:</p>
<textarea rows="1" cols="90" name="textData1" wrap="physical">
<?php echo $theData1; ?>
</textarea>
<p>Enter the first paragraph of text here:<br />
<textarea rows="15" cols="90" name="textData2" wrap="physical">
<?php echo $theData2; ?>
</textarea>
<p>Enter the Second paragraph of text here:</p>
<textarea rows="15" cols="90" name="textData3" wrap="physical">
<?php echo $theData3; ?>
</textarea>
<input type="submit" value="submit" name="submit">
</form>
Content of pageview.php
<?php
$dataFile1 = "datafile1.txt";
$fh = fopen($dataFile1, 'w') or die("can't open file");
$stringData1 = $_POST["textData1"];
fwrite($fh, $stringData1);
fclose($fh);
?>
<?php
$dataFile2 = "datafile2.txt";
$fh = fopen($dataFile2, 'w') or die("can't open file");
$stringData2 = $_POST["textData2"];
fwrite($fh, $stringData2);
fclose($fh);
?>
<?php
$dataFile3 = "datafile3.txt";
$fh = fopen($dataFile3, 'w') or die("can't open file");
$stringData3 = $_POST["textData3"];
fwrite($fh, $stringData3);
fclose($fh);
?>
<?php
$theData1 = file_get_contents('datafile1.txt', true);
$theData2 = file_get_contents('datafile2.txt', true);
$theData3 = file_get_contents('datafile3.txt', true);
?>
<div id="apDiv1"><?php echo $theData1; ?></div>
<div id="apDiv2"><?php echo $theData2; ?></div>
<div id="apDiv3"><?php echo $theData3; ?></div>
Thanks again.