Space aliens -- or Canadians -- stole it. That's my best guess, without seeing a few lines of code. (I'm pretty sure you ought to be using CGI.pm, however.)
| [reply] |
We did not steal your precious variables. But we suspect this human did. We also suspect he is from the land you call Canada.
mitd-Made in the Dark
'Interactive! Paper tape is interactive!
If you don't believe me I can show
you my paper cut scars!'
| [reply] |
after seeing your code, I suspect the problem is as follows: you can see the data you posted in the preview, but when you click on 'Publish new event', all the data is lost.
if this is your problem, then it has nothing to do with variables, nor with Perl at all, but with a misunderstanding of how CGI works. you simply didn't pass anything from the form in the preview() sub (only action=add_data is there), so when your script executes again it obviously has no data.
if you don't post all the data (eg. month, date, year, title, message, etc.) again in hidden fields inside the preview() sub , you will have them empty on the second run.
hope this helps.
cheers,
Aldo
__END__
$_=q,just perl,,s, , another ,,s,$, hacker,,print;
| [reply] [d/l] |
it's difficult to answer your question without seeing some code, but you might want to check whether you've defined the $month variable in an inner block of code, and you're trying to access the value of the variable in an outer block... | [reply] |
Thanks, I hope this can help.
#!/usr/local/bin/perl
use CGI qw/:all/;
$| = 1;
my $q = new CGI;
my $action = $q->param('action');
# Read in all the variables set by the form
CGI::ReadParse(*input);
# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";
$month = $input{'month'};
$date = $input{'date'};
$year = $input{'year'};
#$action = param('action');
#print $action;
$numberoflines = &CountCurrentRecords('events.txt');
if($action eq "add_data"){
print "Your post was sucessful<br>";
#check_event();
add_data();
}
else{
#print "We are not in the Add sub-routine<BR>";
#this is just an example fictitious default subroutine
}
if($action eq "preview"){
#print "<BR>Is this information correct?<br>";
preview();
}
else{
#print "We are not in the Preview sub-routine<br>";
#this is just an example fictitious default subroutine
}
############### BEGIN COUNTCURRENTRECORDS SUBROUTINE #################
+#######
sub CountCurrentRecords {
$number = 1;
my($database) = ($_[0]);
open(DATABASE, "$database");
while ($line=<DATABASE>) {
$number++;
}
$number = 0 if $number < 0;
close(DATABASE);
return $number;
}
######################################################################
+#######
##
## Preview Data Section
##
######################################################################
+######
############### sub preview ########
sub preview{
print "<html>
<HR>
<table border='0' width='100%'>
<tr>
<td width='100%'>
<table border='0' width='100%'>
<tr>
<td width='100%'>
<table border='0' width='100%'>
<tr>
<td width='22%'><font SIZE='+1'color='gray'><B>$month
+$date, $year</B></font></td>
<td width='78%'><font SIZE='+1'color='black'><B>$input
+{'title'}</B></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width='100%'><font SIZE='2'>$input{'message'}</font></td
+>
</tr>
</table>
</td>
</tr>
</table>
<BR>
<form action method='post'>
<input type='hidden' name='action' value='add_data'>
<input type='submit' value=' Publish new event '>
<BR><INPUT type='button' value=' Continue Editing ' onClick='histo
+ry.go(-1)'>
</form>
<BR>
$numberoflines
</html>\n";
}
######################################################################
+#######
##
## Add Data Section
##
######################################################################
+######
############### sub add_data ########
sub add_data{
# Print out a content-type for HTTP/1.0 compatibility
$addfile = "events.txt";
print "$month";
print $month;
#print "We are in the add_data sub-routine<BR>\n";
# Open the file for appending
open (OUT, ">>$addfile") or die "Can't open $addfile\n";
$number = $numberoflines;
$message = $input{'message'};
$line = join '::', $number,$month,$date,$year,$title,$message;
print OUT "$line\n";
close OUT;
}
| [reply] [d/l] |
Short answer:
Your problem is here:
# Read in all the variables set by the form
CGI::ReadParse(*input);
$month = $input{'month'};
$date = $input{'date'};
$year = $input{'year'};
I don't know why not, but ReadParse is not working as you
want it to in this instance. As a result $input{month} is undefined and so $month is too.
Since you're using CGI, and you know how to pull parameters out, I'd suggest you replace this block of code with something more like:
my $month = $q->param('month');
my $date = $q->param('date');
my $year = $q->param('year');
my $title = $q->param('title');
my $message = $q->param('message');
This will fix the problem you've described (and make you aware of a lot more).
Hope this helps.
jarich
| [reply] [d/l] [select] |
Where exactly does $month go from having a value to not having a value? You should add lines like the following until you pinpoint the exact line of code at which it's going bad:
print "1: input-month: \"$input{'month'}\"<BR>\n";
...
print "1: month: \"$month\"<BR>\n";
...
print "2: month: \"$month\"<BR>\n";
...
Add them starting with the first time you reference $month, and then keep adding them until you get to one that doesn't have the value. Or, start in the middle somewhere and do a binary search.
-Make sure to number them or make them unique in some other way so that you can see correlate the output to the code.
-Although maybe not necessary here, quoting the value is useful in general when printing debugging html because you can clearly see extra spaces (newlines, etc.) in the value that get collapsed into a single space or ignored by the browser.
Just adding these print statements and identifying where the value is lost should make it clear to you what's going wrong. If it doesn't, then post the new code and note exactly where the value disappears and it might be clear to someone else here.
It seems like such an ugly and stupid way of debugging but simple print statements are often the quickest way to find bugs of this sort. | [reply] [d/l] |
This may help you uncover some problems and is generally a good idea to include in all your programs.
#!/usr/local/bin/perl -w
use strict;
| [reply] [d/l] |