My script is not recognizing a boolean variable
Posted: Tue May 20, 2003 6:49 pm
Hello all,
Here's my problem: I have a webpage that accepts user input, and write that input into an XML file. It then redisplays the page until the user quits. The first time the user enters data, I want it to write some simple XML headers. So I set up a variable called $headerwritten, which is initially false. The XML headers should only be written if this variable is false. Once the headers are written, the value of the variable changes to true so the headers won't be written each time thru, capice?
This is the first script that gets called:
The relevant include() file includes this code:
If anyone can point out what I'm doing wrong, I'd appreciate it.
Here's my problem: I have a webpage that accepts user input, and write that input into an XML file. It then redisplays the page until the user quits. The first time the user enters data, I want it to write some simple XML headers. So I set up a variable called $headerwritten, which is initially false. The XML headers should only be written if this variable is false. Once the headers are written, the value of the variable changes to true so the headers won't be written each time thru, capice?
This is the first script that gets called:
Code: Select all
<?php
include ("functions_room_builder.php");
$areadesc=HTMLSpecialChars($_POST['areadesc']);
$areaname=HTMLSpecialChars($_POST['areaname']);
$climate=HTMLSpecialChars($_POST['climate']);
$roomnumber=$_POST['roomnumber'];
$roomname=$_POST['roomname'];
$shortdesc=$_POST['shortdesc'];
$longdesc=$_POST['longdesc'];
$inout=$_POST['inout'];
$headerwritten=$_POST['headerwritten'];
$filename = sanatizeFilename($areaname);
echo "Headerwritten = $headerwritten";
if(!$headerwritten)
{
#This never executes even though the variable is false! HELP!
echo "Preparing to write headers!";
writeRoomHeader($areaname, $climate, $areadesc, $headerwritten);
$headerwritten = true;
}
writeRoomDetails($areaname, $roomnumber, $roomname, $shortdesc, $longdesc, $inout);
drawPage();
?>Code: Select all
<?phpfunction drawPage()
{
$areaname = $_POST['areaname'];
$headerwritten = $_POST['headerwritten'];
#Extraneous code to draw a webpage removed for brevity
echo "<INPUT TYPE=HIDDEN NAME=areaname VALUE=$areaname>";
echo "<INPUT TYPE=HIDDEN NAME=headerwritten VALUE=$headerwritten>";
}
function writeRoomDetails($filename, $roomnumber, $roomname, $shortdesc, $longdesc, $inout)
{
$safename = sanatizeFilename($filename);
if (!($fp = fopen($safename, "a"))) die ("Cannot open $safename");
$bodytext = "\n\t<room>";
$bodytext .= "\n\t\t<roomnumber>$roomnumber</roomnumber>";
$bodytext .= "\n\t\t<roomname>$roomname</roomname>";
fwrite($fp, $bodytext);
}
function writeRoomHeader($filename, $climate, $areadesc, $headerwritten)
{
echo "Inside writeRoomHeader creation block.";
$safename = sanatizeFilename($filename);
if (!($fp = fopen($safename, "a"))) die ("Cannot open $safename");
$xmlheader = createXMLHeader($filename, $climate, $areadesc);
fwrite($fp, $xmlheader);
}
function createXMLHeader($filename, $climate, $areadesc)
{
$xmlheader = "<?xml version="1.0"?>";
$xmlheader .= "\n<area name=$filename climate=$climate>";
$xmlheader .="\n<areadesc>$areadesc</areadesc>";
return $xmlheader;
}