Page is a not externally linkable
TomAnthony - 3:02 pm on Apr 5, 2006 (gmt 0)
I am guessing you are curently leaving them blank, so lets work with this. Now you will only want to update an offer if the form has something in that section. Try this: However, this does have a problem -- if the customer wants to have an offer 1, and for there to be no offer 2, then this code won't let them clear offer 2! I'll leave sorting this problem out to you - give it a try and post again if you are struggling.
Hrm, ok. Well there are a few issues, the first being the form your customer sees - are the fields blank or do they have the previous offer values in them?
<?php
$filename = "offer1.txt";
$heading = $_POST['offersHeading'];
$body = $_POST['offersBody'];
$text = '<p><h2>'.$heading.'</h2>'.$body.'</p>';
$filename2 = "offer2.txt";
$heading2 = $_POST['offersHeading2'];
$body2 = $_POST['offersBody2'];
$text2 = '<p><h2>'.$heading2.'</h2>'.$body2.'</p>';
// if the heading was not empty, proceed with writing file.
if (!empty($heading))
{
$fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
if ($fp) {
fwrite ($fp, $text);
fclose ($fp);
echo ("<strong>Special Offer Number 1</strong> has been updated. To review your updates, go to the <a href=\"special-offers.php\">Special Offers</a> page.");
}
else {
echo ("There was an error updating Special Offer 1. Please go back and try again.");
}
}
// if the heading was not empty, proceed with writing file.
if (!empty($heading2))
{
$fp2 = fopen ($filename2, "w"); # w = write to the file only, create file if it does not exist, discard existing content
if ($fp2) {
fwrite ($fp2, $text2);
fclose ($fp2);
echo ("<p><strong>Special Offer Number 2</strong> has been updated. To review your updates, go to the <a href=\"special-offers.php\">Special Offers</a> page.</p>");
}
else {
echo ("There was an error updating Special Offer 2. Please go back and try again.");
}
}
?>