bingoldsby
Technical User
In another thread, I have been asking for assistance getting an HTML form to call a script which will open an XML file, find a specific line, and add another line using the form's input data to modify that new line. (it's adding an email address to a whitelist)
I have the form and a script, but the script has a problem which I can not discern and fix. Hoping for help here.
The problem seems to be that the script can not open the xml file to gather it all up into an "array of strings." The webserver (Apache on Windows) gives that error message in it's error log. Depending on how and from where I try to access the cgi, there are other problems, it seems.
Here is the script.
There may be other problems with this script, but this is the only one I have been able to identify so far. The section of the script: "#read XML file to array of strings" and in particular, the line: "open(XML, $xml_file) || die("Could not open file!");" is where the first and halting error occours when the script is run directly from a browser (not via the form - there other issues there for later)
I'll post or email the other parts of the puzzle - the form and the xml file for anyone who can help. It seems like this should be an easy go for several persons who hang out here, according to what I've been reading in other threads.
I'm very hopeful on getting a solution to this problem.
Thank you all very much.
Brian - Union Gospel Mission
Yakima, WA
I have the form and a script, but the script has a problem which I can not discern and fix. Hoping for help here.
The problem seems to be that the script can not open the xml file to gather it all up into an "array of strings." The webserver (Apache on Windows) gives that error message in it's error log. Depending on how and from where I try to access the cgi, there are other problems, it seems.
Here is the script.
Code:
#!c:\perl\bin\perl.exe
# The following accepts the data from the form and splits it into its component parts
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# Read XML file to array of strings
$xml_file="c:\prpgram files\apache group\apache\cgi-bin\whitelist_test.xml";
open(XML, $xml_file) || die("Could not open file!");
@xml=<XML>;
close(XML);
# Write XML back to file, adding email
open(XML,">>$xml_file") || die("Cannot Open File");
foreach $line (@xml) {
print XML $line;
if ($line == "<expression casesensitive=\"no\" type=\"regex\" onmatch=\"score += 1\">zyxxxyz</expression>") {
print XML "<expression casesensitive=\"no\" type=\"regex\" onmatch=\"score += 1\">$FORM{email}</expression>"
}
}
close(XML);
# Write the thank you page
print "Content-type: text/html\n\n";
print <<EndStart;
<html>
<head>
<title>Thank You</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<h1>Thank You</h1>
<p>Your email address has been stored.</p>
</body>
</html>
EndStart
There may be other problems with this script, but this is the only one I have been able to identify so far. The section of the script: "#read XML file to array of strings" and in particular, the line: "open(XML, $xml_file) || die("Could not open file!");" is where the first and halting error occours when the script is run directly from a browser (not via the form - there other issues there for later)
I'll post or email the other parts of the puzzle - the form and the xml file for anyone who can help. It seems like this should be an easy go for several persons who hang out here, according to what I've been reading in other threads.
I'm very hopeful on getting a solution to this problem.
Thank you all very much.
Brian - Union Gospel Mission
Yakima, WA