: : [b][red]This message was edited by mdw1982 at 2004-2-19 12:10:16[/red][/b][hr]
: : : Well, the bit of code we can look to is fairly small at least.
: : :
: : : [code]sub search_cust_entry
: : : {
: : : my $recnum;
: : : my $linkto;
: : : &read_config;
: : :
: : : # connect to the database
: : : $dbh = DBI->connect("DBI:mysql:$conflist{'db_name'}:$conflist{'db_host'}",
: : : "$conflist{'db_user'}","$conflist{'db_passwd'}") or die "Cannot Connect: $!
";
: : :
: : :
: : : # incoming form data
: : : if ( $FORM{'search_name'} )
: : : {
: : : print "Content-Type: text/html
";
: : : [/code]
: : :
: : : It must be in that section. Otherwise, we'd get a header. So either:-
: : :
: : : 1) The sub is never called.
: : : 2) Bad things happen in &read_config.
: : : 3) if ( $FORM{'search_name'} ) evaluates false so no header is printed.
: : :
: : : I suspect it may be (1). What's your code for deciding whether to call the sub?
: : :
: : : Jonathan
: :
: : Well &read_config; calls a sub in the admin.pl file that reads the config file and gets db name and db host information. the db username and passwd is being gathered from a cookie, at least thats the plan once I can get past this point. I'm calling the getCookie sub in other parts of the program and that works ok.
: :
: : I suspected that I wasn't getting any header being sent to the browser so I place the header call at the beginning of the sub, but that didn't make any difference at the time.
: :
: : Edit: I just tested it again, this time calling the getCookie sub for the db user and passwd and now its printing the first data page, but there's no header coming out. I'm beginning to think this blasted program is haunted!
: :
: Question - what is the "enter_cust_search" for in the query string? Should it not be more like:-
: enter_cust_search=1
: What is it set to the first time the page loads?
the "enter_cust_search" is the query string being sent to the customer.pl program so it knows which sub to use. The first time this is called the whole thing looks like this:
blahblahblah
Its going into the program as the value for $ENV{'QUERY_STRING'}. The test for that looks like this:
if ( $ENV{'QUERY_STRING'} eq "enter_cust_search" ){ &search_cust_entry; }
--
Mark
"If I can't code I'm not going to be a happy camper!"
Comments
:
Well, there's your problem. The query string is not equal to "enter_cust_search" because there are other things tacked after it. You need to check if the query string starts with this text, e.g.
&search_cust_entry if $ENV{'QUERY_STRING'} =~ /^enter_cust_search/;
OK, I refactored it a bit too. ;-) You may want to consider using substr instead of pattern matching, though I'm sure you can manage that bit. :-)
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
: : if ( $ENV{'QUERY_STRING'} eq "enter_cust_search" ){ &search_cust_entry; }
: :
: Well, there's your problem. The query string is not equal to "enter_cust_search" because there are other things tacked after it. You need to check if the query string starts with this text, e.g.
:
: &search_cust_entry if $ENV{'QUERY_STRING'} =~ /^enter_cust_search/;
:
: OK, I refactored it a bit too. ;-) You may want to consider using substr instead of pattern matching, though I'm sure you can manage that bit. :-)
:
: Jonathan
OMG!!! thats it! I can't believe I didn't see that. It was right there under my nose the whole time! Geez! I can't wait to plug that in and watch it work.
EDIT: 2004-02-21 00:28
;-) well, the 500 error is gone now and I'm not getting any error messages in the console when tailing the error log when the second screen comes up, but it comes up blank. I have a feeling its dying cause the header isn't printing correctly. I'm gonna hard code the header info for this part and see what happens.
thanks,
--
Mark
"If I can't code I'm not going to be a happy camper!"
: : : if ( $ENV{'QUERY_STRING'} eq "enter_cust_search" ){ &search_cust_entry; }
: : :
: : Well, there's your problem. The query string is not equal to "enter_cust_search" because there are other things tacked after it. You need to check if the query string starts with this text, e.g.
: :
: : &search_cust_entry if $ENV{'QUERY_STRING'} =~ /^enter_cust_search/;
: :
: : OK, I refactored it a bit too. ;-) You may want to consider using substr instead of pattern matching, though I'm sure you can manage that bit. :-)
: :
: : Jonathan
:
: OMG!!! thats it! I can't believe I didn't see that. It was right there under my nose the whole time! Geez! I can't wait to plug that in and watch it work.
:
Well, that's one more problem down. Welcome to the world of debugging scripts...
: EDIT: 2004-02-21 00:28
:
: ;-) well, the 500 error is gone now and I'm not getting any error messages in the console when tailing the error log when the second screen comes up, but it comes up blank. I have a feeling its dying cause the header isn't printing correctly. I'm gonna hard code the header info for this part and see what happens.
:
I would suggest throwing a few print statements in to see where execution goes. e.g. put
print "At A
";
Somewhere, then if it prints "At A" to the browser then you know it reached that point in the code. Knowing where the script is failing and why it displays nothing will get you a lot further to solving the problem.
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
: :
: Well, that's one more problem down. Welcome to the world of debugging scripts...
:
: : EDIT: 2004-02-21 00:28
: :
: : ;-) well, the 500 error is gone now and I'm not getting any error messages in the console when tailing the error log when the second screen comes up, but it comes up blank. I have a feeling its dying cause the header isn't printing correctly. I'm gonna hard code the header info for this part and see what happens.
: :
: I would suggest throwing a few print statements in to see where execution goes. e.g. put
: print "At A
";
: Somewhere, then if it prints "At A" to the browser then you know it reached that point in the code. Knowing where the script is failing and why it displays nothing will get you a lot further to solving the problem.
:
: Jonathan
will do... I'll let ya know what happens next.
--
Mark
"If I can't code I'm not going to be a happy camper!"
: :
: I would suggest throwing a few print statements in to see where execution goes. e.g. put
: print "At A
";
: Somewhere, then if it prints "At A" to the browser then you know it reached that point in the code. Knowing where the script is failing and why it displays nothing will get you a lot further to solving the problem.
:
: Jonathan
So far, and I'll post the current code for this sub below, it appears its dying on the second time through when the search term is supposed to be passed in. _thats_ where its dying. First I'll post the code, and then the onscreen results of the first and second run. you'll notice at the end of the sub that I added an else statement so that it could say something other then just nothing to let me know that indeed the search term was getting passed in. Not really necessary, but it felt right.
[code]
sub search_cust_entry
{
print "Content-Type: text/html
";
print "BEGINNING: just sent the content type header
";
`sleep 2`;
my @search_info = "";
my @search_meta = "";
my @search_title = "Results of Customer Search";
header( @search_title, @search_meta );
print "A: just after the header call.
";
`sleep 2`;
my $recnum;
my $linkto;
&read_config;
print "B: I've read the config file that I called from the admin.pl
";
`sleep 2`;
&cookieCheck;
my ( $cookieID, $cookieUser, $cookiePasswd ) = &getCookie;
print "C: checked for a cookie and gotten the cookie.
sleeping for 4 seconds.
";
`sleep 2`;
print "D: connecting to db.
";
`sleep 2`;
# connect to the database
$dbh = DBI->connect("DBI:mysql:$conflist{'db_name'}:$conflist{'db_host'}","$cookieUser","$cookiePasswd") or die "Cannot Connect: $!
";
print "E: passing in the search term.
";
`sleep 2`;
# incoming form data
if ( $FORM{'search_name'} ne "" ) [red]# second time through dies here[/red]
{
print "F: Got the search term. it is $FORM{'search_name'}
";
`sleep 2`;
my $rowcount = 0;
my $recnum = $FORM{'recnum'} =~ /^d+$/ ? $FORM{'recnum'} : 1;
my $numrows;
my $search_term = "%$FORM{'search_name'}%";
$sth = $dbh->prepare("describe customer") or die "Sorry...there was an error: $!
";
$sth->execute;
my @dbField;
my $bgcolor;
while ( $row_hash = $sth->fetchrow_hashref )
{
my $fieldname = $row_hash->{'Field'};
push(@dbField, $fieldname);
}
$sth->finish;
# get count for number of records which meet search terms
$sth = $dbh->prepare("select count(customer_name) as cust_count from customer where customer_name like '$search_term'") or die "Something is wrong with and I cannot continue: $!
";
$sth->execute;
$numrows = $sth->fetchrow_array();
$sth->finish;
#print "@dbField
";
my $temp_term = $search_term;
$temp_term =~ s/%//g;
print "Your Search Term Was: $temp_term
";
# Check if we have a valid record number, otherwise use 0.
$recnum = 1 if $recnum > $numrows || $recnum < 1;
# Take one off it (limit uses base 0).
$recnum --;
# We only need to print one table - only one per page.
print "
";
foreach my $FIELD_NAME ( @dbField )
{
chomp( $FIELD_NAME );
$sth = $dbh->prepare("select $FIELD_NAME from customer where customer_name like '$search_term' limit $recnum,1") or die "Sorry...there was an error: $!
";
$sth->execute;
while ( $row_hash = $sth->fetchrow_hashref ) #### begin While loop
{
my $field_value = $row_hash->{$FIELD_NAME};
$FIELD_NAME =~ s/_/ /;
if ( ($rowcount % 2) > 0 )
{
$bgcolor = "#FFFFFF";
}
else
{
$bgcolor = "#E9E9E9";
}
if ( $FIELD_NAME eq "customer number" )
{
print "
";
print "
";
print "$field_value
";
print "
";
print "
print "
}
else
{
print "
";
print "
print "
}
$rowcount++;
} ### end while loop
} # end of $FIELD_NAME foreach loop
print "
print "$rowcount
";
# Add code to print next and previous links, e.g.
if ($recnum > 0) {
# clean search term value
$search_term =~ s/%//g;
print qq{
print qq{Prev };
print qq{
}
if ($recnum + 1 < $numrows)
{
# clean search term value
$search_term =~ s/%//g;
$linkto = $recnum + 1;
print qq{
print qq{Next };
print qq{
}
&footer;
exit;
}
else
{
&header;
print "I'm sorry...I didn't understand the question.
";
&footer;
exit;
}
}
[/code]
first ( initial ) time the search param is passed into the program.
RESULTS:
BEGINNING: just sent the content type header
A: just after the header call.
B: I've read the config file that I called from the admin.pl
C: checked for a cookie and gotten the cookie.
sleeping for 4 seconds.
E: passing in the search term.
F: Got the search term. it is don
Your Search Term Was: don
( RESULTS ) screen full of good data and a "next" link at the bottom for next screen with the URL: http://mdw1982.dyndns.org/simpletrack/cgi-bin/customer.pl?enter_cust_search&search_name=don&recnum=1
second time ( when the Next link is clicked to show second screen )
RESULTS:
BEGINNING: just sent the content type header
A: just after the header call.
B: I've read the config file that I called from the admin.pl
C: checked for a cookie and gotten the cookie.
sleeping for 4 seconds.
E: passing in the search term.
I'm sorry...I didn't understand the question.
( RESULTS ) big empty screen...
--
Mark
"If I can't code I'm not going to be a happy camper!"
: : :
: : I would suggest throwing a few print statements in to see where execution goes. e.g. put
: : print "At A
";
: : Somewhere, then if it prints "At A" to the browser then you know it reached that point in the code. Knowing where the script is failing and why it displays nothing will get you a lot further to solving the problem.
: :
: : Jonathan
:
: So far, and I'll post the current code for this sub below, it appears its dying on the second time through when the search term is supposed to be passed in. _thats_ where its dying. First I'll post the code, and then the onscreen results of the first and second run. you'll notice at the end of the sub that I added an else statement so that it could say something other then just nothing to let me know that indeed the search term was getting passed in. Not really necessary, but it felt right.
:
: [code]
: sub search_cust_entry
: {
: print "Content-Type: text/html
";
:
: print "BEGINNING: just sent the content type header
";
: `sleep 2`;
:
: my @search_info = "";
: my @search_meta = "";
: my @search_title = "Results of Customer Search";
: header( @search_title, @search_meta );
:
: print "A: just after the header call.
";
: `sleep 2`;
:
: my $recnum;
: my $linkto;
: &read_config;
:
: print "B: I've read the config file that I called from the admin.pl
";
: `sleep 2`;
:
: &cookieCheck;
: my ( $cookieID, $cookieUser, $cookiePasswd ) = &getCookie;
:
: print "C: checked for a cookie and gotten the cookie. sleeping for 4 seconds.
";
: `sleep 2`;
:
: print "D: connecting to db.
";
: `sleep 2`;
:
: # connect to the database
: $dbh = DBI->connect("DBI:mysql:$conflist{'db_name'}:$conflist{'db_host'}","$cookieUser","$cookiePasswd") or die "Cannot Connect: $!
";
:
:
: print "E: passing in the search term.
";
: `sleep 2`;
: # incoming form data
: if ( $FORM{'search_name'} ne "" ) [red]# second time through dies here[/red]
: {
: print "F: Got the search term. it is $FORM{'search_name'}
";
: `sleep 2`;
:
: my $rowcount = 0;
: my $recnum = $FORM{'recnum'} =~ /^d+$/ ? $FORM{'recnum'} : 1;
: my $numrows;
: my $search_term = "%$FORM{'search_name'}%";
: $sth = $dbh->prepare("describe customer") or die "Sorry...there was an error: $!
";
: $sth->execute;
: my @dbField;
: my $bgcolor;
:
: while ( $row_hash = $sth->fetchrow_hashref )
: {
: my $fieldname = $row_hash->{'Field'};
: push(@dbField, $fieldname);
: }
: $sth->finish;
:
: # get count for number of records which meet search terms
: $sth = $dbh->prepare("select count(customer_name) as cust_count from customer where customer_name like '$search_term'") or die "Something is wrong with and I cannot continue: $!
";
: $sth->execute;
: $numrows = $sth->fetchrow_array();
: $sth->finish;
:
: #print "@dbField
";
: my $temp_term = $search_term;
: $temp_term =~ s/%//g;
: print "Your Search Term Was: $temp_term
";
:
: # Check if we have a valid record number, otherwise use 0.
: $recnum = 1 if $recnum > $numrows || $recnum < 1;
:
: # Take one off it (limit uses base 0).
: $recnum --;
:
: # We only need to print one table - only one per page.
: print "
";
: foreach my $FIELD_NAME ( @dbField )
: {
: chomp( $FIELD_NAME );
: $sth = $dbh->prepare("select $FIELD_NAME from customer where customer_name like '$search_term' limit $recnum,1") or die "Sorry...there was an error: $!
";
: $sth->execute;
: while ( $row_hash = $sth->fetchrow_hashref ) #### begin While loop
: {
: my $field_value = $row_hash->{$FIELD_NAME};
: $FIELD_NAME =~ s/_/ /;
: if ( ($rowcount % 2) > 0 )
: {
: $bgcolor = "#FFFFFF";
: }
: else
: {
: $bgcolor = "#E9E9E9";
: }
: if ( $FIELD_NAME eq "customer number" )
: {
: print "
";
: print "
";
: print "$field_value
";
: print "
";
: print "
: print "
: }
: else
: {
: print "
";
: print "
: print "
: }
: $rowcount++;
: } ### end while loop
: } # end of $FIELD_NAME foreach loop
: print "
: print "$rowcount
";
:
: # Add code to print next and previous links, e.g.
: if ($recnum > 0) {
: # clean search term value
: $search_term =~ s/%//g;
: print qq{
: print qq{Prev };
: print qq{
: }
: if ($recnum + 1 < $numrows)
: {
: # clean search term value
: $search_term =~ s/%//g;
: $linkto = $recnum + 1;
: print qq{
: print qq{Next };
: print qq{
: }
: &footer;
: exit;
: }
: else
: {
: &header;
: print "I'm sorry...I didn't understand the question.
";
: &footer;
: exit;
: }
: }
:
: [/code]
:
: first ( initial ) time the search param is passed into the program.
: RESULTS:
: BEGINNING: just sent the content type header
:
: A: just after the header call.
:
: B: I've read the config file that I called from the admin.pl
:
: C: checked for a cookie and gotten the cookie.
: sleeping for 4 seconds.
:
:
:
: E: passing in the search term.
:
: F: Got the search term. it is don
:
: Your Search Term Was: don
: ( RESULTS ) screen full of good data and a "next" link at the bottom for next screen with the URL: http://mdw1982.dyndns.org/simpletrack/cgi-bin/customer.pl?enter_cust_search&search_name=don&recnum=1
:
: second time ( when the Next link is clicked to show second screen )
: RESULTS:
: BEGINNING: just sent the content type header
:
: A: just after the header call.
:
: B: I've read the config file that I called from the admin.pl
:
: C: checked for a cookie and gotten the cookie.
: sleeping for 4 seconds.
:
:
:
: E: passing in the search term.
:
: I'm sorry...I didn't understand the question.
: ( RESULTS ) big empty screen...
:
Your code is working just fine. The problem is that $FORM{'search_name'} really is empty! And why? Well, you do this:-
: print qq{Next };
Maybe I'm missing something, but where on earth does $search_term come from? I can't find the variable used anywhere else... You should probably have put:-
print qq{Next };
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
: : : :
: : : I would suggest throwing a few print statements in to see where execution goes. e.g. put
: : : print "At A
";
: : : Somewhere, then if it prints "At A" to the browser then you know it reached that point in the code. Knowing where the script is failing and why it displays nothing will get you a lot further to solving the problem.
: : :
: : : Jonathan
: :
: : So far, and I'll post the current code for this sub below, it appears its dying on the second time through when the search term is supposed to be passed in. _thats_ where its dying. First I'll post the code, and then the onscreen results of the first and second run. you'll notice at the end of the sub that I added an else statement so that it could say something other then just nothing to let me know that indeed the search term was getting passed in. Not really necessary, but it felt right.
: :
: : [code]
: : sub search_cust_entry
: : {
: : print "Content-Type: text/html
";
: :
: : print "BEGINNING: just sent the content type header
";
: : `sleep 2`;
: :
: : my @search_info = "";
: : my @search_meta = "";
: : my @search_title = "Results of Customer Search";
: : header( @search_title, @search_meta );
: :
: : print "A: just after the header call.
";
: : `sleep 2`;
: :
: : my $recnum;
: : my $linkto;
: : &read_config;
: :
: : print "B: I've read the config file that I called from the admin.pl
";
: : `sleep 2`;
: :
: : &cookieCheck;
: : my ( $cookieID, $cookieUser, $cookiePasswd ) = &getCookie;
: :
: : print "C: checked for a cookie and gotten the cookie. sleeping for 4 seconds.
";
: : `sleep 2`;
: :
: : print "D: connecting to db.
";
: : `sleep 2`;
: :
: : # connect to the database
: : $dbh = DBI->connect("DBI:mysql:$conflist{'db_name'}:$conflist{'db_host'}","$cookieUser","$cookiePasswd") or die "Cannot Connect: $!
";
: :
: :
: : print "E: passing in the search term.
";
: : `sleep 2`;
: : # incoming form data
: : if ( $FORM{'search_name'} ne "" ) [red]# second time through dies here[/red]
: : {
: : print "F: Got the search term. it is $FORM{'search_name'}
";
: : `sleep 2`;
: :
: : my $rowcount = 0;
: : my $recnum = $FORM{'recnum'} =~ /^d+$/ ? $FORM{'recnum'} : 1;
: : my $numrows;
: : my [blue]$search_term[/blue] = "%$FORM{'search_name'}%";
: : $sth = $dbh->prepare("describe customer") or die "Sorry...there was an error: $!
";
: : $sth->execute;
: : my @dbField;
: : my $bgcolor;
: :
: : while ( $row_hash = $sth->fetchrow_hashref )
: : {
: : my $fieldname = $row_hash->{'Field'};
: : push(@dbField, $fieldname);
: : }
: : $sth->finish;
: :
: : # get count for number of records which meet search terms
: : $sth = $dbh->prepare("select count(customer_name) as cust_count from customer where customer_name like '$search_term'") or die "Something is wrong with and I cannot continue: $!
";
: : $sth->execute;
: : $numrows = $sth->fetchrow_array();
: : $sth->finish;
: :
: : #print "@dbField
";
: : my $temp_term = $search_term;
: : $temp_term =~ s/%//g;
: : print "Your Search Term Was: $temp_term
";
: :
: : # Check if we have a valid record number, otherwise use 0.
: : $recnum = 1 if $recnum > $numrows || $recnum < 1;
: :
: : # Take one off it (limit uses base 0).
: : $recnum --;
: :
: : # We only need to print one table - only one per page.
: : print "
";
: : foreach my $FIELD_NAME ( @dbField )
: : {
: : chomp( $FIELD_NAME );
: : $sth = $dbh->prepare("select $FIELD_NAME from customer where customer_name like '$search_term' limit $recnum,1") or die "Sorry...there was an error: $!
";
: : $sth->execute;
: : while ( $row_hash = $sth->fetchrow_hashref ) #### begin While loop
: : {
: : my $field_value = $row_hash->{$FIELD_NAME};
: : $FIELD_NAME =~ s/_/ /;
: : if ( ($rowcount % 2) > 0 )
: : {
: : $bgcolor = "#FFFFFF";
: : }
: : else
: : {
: : $bgcolor = "#E9E9E9";
: : }
: : if ( $FIELD_NAME eq "customer number" )
: : {
: : print "
";
: : print "
";
: : print "$field_value
";
: : print "
";
: : print "
: : print "
: : }
: : else
: : {
: : print "
";
: : print "
: : print "
: : }
: : $rowcount++;
: : } ### end while loop
: : } # end of $FIELD_NAME foreach loop
: : print "
: : print "$rowcount
";
: :
: : # Add code to print next and previous links, e.g.
: : if ($recnum > 0) {
: : # clean search term value
: : $search_term =~ s/%//g;
: : print qq{
: : print qq{Prev };
: : print qq{
: : }
: : if ($recnum + 1 < $numrows)
: : {
: : # clean search term value
: : $search_term =~ s/%//g;
: : $linkto = $recnum + 1;
: : print qq{
: : print qq{Next };
: : print qq{
: : }
: : &footer;
: : exit;
: : }
: : else
: : {
: : &header;
: : print "I'm sorry...I didn't understand the question.
";
: : &footer;
: : exit;
: : }
: : }
: :
: : [/code]
: Your code is working just fine. The problem is that $FORM{'search_name'} really is empty! And why? Well, you do this:-
:
: : print qq{Next };
:
: Maybe I'm missing something, but where on earth does $search_term come from? I can't find the variable used anywhere else... You should probably have put:-
:
: print qq{Next };
Hi Jonathan,
The variable $search_term is now highlighted in blue, but just to make sure I relaced $search_term with $FORM{'search_name'} for the bit with the "next" link, and its still doing the same thing. apparently the search term, even though it is visible in the URL, and is making it that far, isn't being passed back into the program from the screen when the next screen is called for. This is definately a mystery to me because I don't really see the reason this is happening.
--
Mark
"If I can't code I'm not going to be a happy camper!"
: : : : :
: : : : I would suggest throwing a few print statements in to see where execution goes. e.g. put
: : : : print "At A
";
: : : : Somewhere, then if it prints "At A" to the browser then you know it reached that point in the code. Knowing where the script is failing and why it displays nothing will get you a lot further to solving the problem.
: : : :
: : : : Jonathan
: : :
: : : So far, and I'll post the current code for this sub below, it appears its dying on the second time through when the search term is supposed to be passed in. _thats_ where its dying. First I'll post the code, and then the onscreen results of the first and second run. you'll notice at the end of the sub that I added an else statement so that it could say something other then just nothing to let me know that indeed the search term was getting passed in. Not really necessary, but it felt right.
: : :
: : : [code]
: : : sub search_cust_entry
: : : {
: : : print "Content-Type: text/html
";
: : :
: : : print "BEGINNING: just sent the content type header
";
: : : `sleep 2`;
: : :
: : : my @search_info = "";
: : : my @search_meta = "";
: : : my @search_title = "Results of Customer Search";
: : : header( @search_title, @search_meta );
: : :
: : : print "A: just after the header call.
";
: : : `sleep 2`;
: : :
: : : my $recnum;
: : : my $linkto;
: : : &read_config;
: : :
: : : print "B: I've read the config file that I called from the admin.pl
";
: : : `sleep 2`;
: : :
: : : &cookieCheck;
: : : my ( $cookieID, $cookieUser, $cookiePasswd ) = &getCookie;
: : :
: : : print "C: checked for a cookie and gotten the cookie. sleeping for 4 seconds.
";
: : : `sleep 2`;
: : :
: : : print "D: connecting to db.
";
: : : `sleep 2`;
: : :
: : : # connect to the database
: : : $dbh = DBI->connect("DBI:mysql:$conflist{'db_name'}:$conflist{'db_host'}","$cookieUser","$cookiePasswd") or die "Cannot Connect: $!
";
: : :
: : :
: : : print "E: passing in the search term.
";
: : : `sleep 2`;
: : : # incoming form data
: : : if ( $FORM{'search_name'} ne "" ) [red]# second time through dies here[/red]
: : : {
: : : print "F: Got the search term. it is $FORM{'search_name'}
";
: : : `sleep 2`;
: : :
: : : my $rowcount = 0;
: : : my $recnum = $FORM{'recnum'} =~ /^d+$/ ? $FORM{'recnum'} : 1;
: : : my $numrows;
: : : my [blue]$search_term[/blue] = "%$FORM{'search_name'}%";
: : : $sth = $dbh->prepare("describe customer") or die "Sorry...there was an error: $!
";
: : : $sth->execute;
: : : my @dbField;
: : : my $bgcolor;
: : :
: : : while ( $row_hash = $sth->fetchrow_hashref )
: : : {
: : : my $fieldname = $row_hash->{'Field'};
: : : push(@dbField, $fieldname);
: : : }
: : : $sth->finish;
: : :
: : : # get count for number of records which meet search terms
: : : $sth = $dbh->prepare("select count(customer_name) as cust_count from customer where customer_name like '$search_term'") or die "Something is wrong with and I cannot continue: $!
";
: : : $sth->execute;
: : : $numrows = $sth->fetchrow_array();
: : : $sth->finish;
: : :
: : : #print "@dbField
";
: : : my $temp_term = $search_term;
: : : $temp_term =~ s/%//g;
: : : print "Your Search Term Was: $temp_term
";
: : :
: : : # Check if we have a valid record number, otherwise use 0.
: : : $recnum = 1 if $recnum > $numrows || $recnum < 1;
: : :
: : : # Take one off it (limit uses base 0).
: : : $recnum --;
: : :
: : : # We only need to print one table - only one per page.
: : : print "
";
: : : foreach my $FIELD_NAME ( @dbField )
: : : {
: : : chomp( $FIELD_NAME );
: : : $sth = $dbh->prepare("select $FIELD_NAME from customer where customer_name like '$search_term' limit $recnum,1") or die "Sorry...there was an error: $!
";
: : : $sth->execute;
: : : while ( $row_hash = $sth->fetchrow_hashref ) #### begin While loop
: : : {
: : : my $field_value = $row_hash->{$FIELD_NAME};
: : : $FIELD_NAME =~ s/_/ /;
: : : if ( ($rowcount % 2) > 0 )
: : : {
: : : $bgcolor = "#FFFFFF";
: : : }
: : : else
: : : {
: : : $bgcolor = "#E9E9E9";
: : : }
: : : if ( $FIELD_NAME eq "customer number" )
: : : {
: : : print "
";
: : : print "
";
: : : print "$field_value
";
: : : print "
";
: : : print "
: : : print "
: : : }
: : : else
: : : {
: : : print "
";
: : : print "
: : : print "
: : : }
: : : $rowcount++;
: : : } ### end while loop
: : : } # end of $FIELD_NAME foreach loop
: : : print "
: : : print "$rowcount
";
: : :
: : : # Add code to print next and previous links, e.g.
: : : if ($recnum > 0) {
: : : # clean search term value
: : : $search_term =~ s/%//g;
: : : print qq{
: : : print qq{Prev };
: : : print qq{
: : : }
: : : if ($recnum + 1 < $numrows)
: : : {
: : : # clean search term value
: : : $search_term =~ s/%//g;
: : : $linkto = $recnum + 1;
: : : print qq{
: : : print qq{Next };
: : : print qq{
: : : }
: : : &footer;
: : : exit;
: : : }
: : : else
: : : {
: : : &header;
: : : print "I'm sorry...I didn't understand the question.
";
: : : &footer;
: : : exit;
: : : }
: : : }
: : :
: : : [/code]
:
: : Your code is working just fine. The problem is that $FORM{'search_name'} really is empty! And why? Well, you do this:-
: :
: : : print qq{Next };
: :
: : Maybe I'm missing something, but where on earth does $search_term come from? I can't find the variable used anywhere else... You should probably have put:-
: :
: : print qq{Next };
:
: Hi Jonathan,
:
: The variable $search_term is now highlighted in blue, but just to make sure I relaced $search_term with $FORM{'search_name'} for the bit with the "next" link, and its still doing the same thing. apparently the search term, even though it is visible in the URL, and is making it that far, isn't being passed back into the program from the screen when the next screen is called for. This is definately a mystery to me because I don't really see the reason this is happening.
:
That's really strange. If it appears in the query string, that only points at a bug in your form handling code, though I'd imagine that wouldn't have taken so long to surface? Paste the URL you see for the links in here, and maybe your form handler code.
*confused*
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
:
: *confused*
:
: Jonathan
A real brain puzzler, eh? I'm not surprised. By that I mean when I was in college learning COBOL and CICS I managed to bring down CICS four times in once evening on the S390. :-) After the last time my professor came over and pointed out the error in my code that was causing the problem. I was close, but just couldn't see the problem.
anyhow, I'm as stumped as you are as to why the $search_term value isn't making it into the program from the first page display. I've since recoded the entire subroutine and its working nicely now, but not the way I wanted it to work.
The link being displayed when search term entered is "don":
http://amicro.dyndns.org/simpletrack/cgi-bin/customer.old.pl?enter_cust_search&search_name=don&recnum=1
At the top of the program there are a few "if" statements testing the query string coming in to know which sub routine to use. The one testing for the search sub looks like this:
if ( $ENV{'QUERY_STRING'} =~ /^enter_cust_search/ ){ &search_cust_entry; }
Down inside the actual sub that is supposed to do the work there's a variable being set to receive the search term and that looks like this. Mind you, it works just fine the first time, but dies on the second time through.
[code]
sub search_cust_entry
{
# setting the variable for the search term
my $search_term = $FORM{'search_name'};
# lots more code to do the work
....
}
[/code]
Since I've not used this sort of method to pass information and commands to a program before apart from passing in a query string, this manner of doing things is foreign to me to say the least. I'm not real clear on whether doing it this way is using the post of get method.
--
Mark
"If I can't code I'm not going to be a happy camper!"
: was in college learning COBOL and CICS I managed to bring down CICS
: four times in once evening on the S390. :-) After the last time my
: professor came over and pointed out the error in my code that was
: causing the problem. I was close, but just couldn't see the problem.
:
The last time I bought down a machine here at uni was when I got curious how well a Linux box could handle me doing...
perl -e 'fork() while 1' &
The box was unusable within seconds. Ooops.
: anyhow, I'm as stumped as you are as to why the $search_term value
: isn't making it into the program from the first page display. I've
: since recoded the entire subroutine and its working nicely now, but
: not the way I wanted it to work.
:
: The link being displayed when search term entered is "don":
: http://amicro.dyndns.org/simpletrack/cgi-bin/customer.old.pl?enter_cust_search&search_name=don&recnum=1
:
: At the top of the program there are a few "if" statements testing
: the query string coming in to know which sub routine to use. The one
: testing for the search sub looks like this:
:
: if ( $ENV{'QUERY_STRING'} =~ /^enter_cust_search/ ){ &search_cust_entry; }
:
: Down inside the actual sub that is supposed to do the work there's a
: variable being set to receive the search term and that looks like
: this. Mind you, it works just fine the first time, but dies on the
: second time through.
:
: [code]
: sub search_cust_entry
: {
: # setting the variable for the search term
: my $search_term = $FORM{'search_name'};
:
: # lots more code to do the work
: ....
: }
: [/code]
:
: Since I've not used this sort of method to pass information and
: commands to a program before apart from passing in a query string,
: this manner of doing things is foreign to me to say the least. I'm
: not real clear on whether doing it this way is using the post of get
: method.
:
OK, let's see your form parsing code. It looks like we have an interesting mix of GET and POST going on here. GET is where data being sent is put in the query string. With a POST the data is not put in the query string, but sent "seperately". I'm now guessing $FORM only contains the results of a POST, not a GET.
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
:
: Jonathan
Hi Jonathan,
sorry its taken me a little while to get back and post. Its been crazy at work this week and till I get home I'm fried and don't even turn on the computer.
below is the code I'm using to parse the info coming back in from the form.
[code]
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@appdata = split(/&/, $buffer);
foreach $appdata (@appdata) {
($name, $value) = split(/=/, $appdata);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
[/code]
I've been using this block of code for quite a while to parse data coming in from all the forms i've ever used.
--
Mark
"If I can't code I'm not going to be a happy camper!"
: : interesting mix of GET and POST going on here. GET is where data
: : being sent is put in the query string. With a POST the data is
: : not put in the query string, but sent "seperately". I'm now
: : guessing $FORM only contains the results of a POST, not a GET.
: :
: sorry its taken me a little while to get back and post. Its been
: crazy at work this week and till I get home I'm fried and don't even
: turn on the computer.
:
Even if you had, you most likely wouldn't have got an answer much more quickly. I've spent the last couple of days being pretty unwell, and have barely touched my computer either. :-(
: below is the code I'm using to parse the info coming back in from
: the form.
:
: [code]
: read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
: @appdata = split(/&/, $buffer);
:
: foreach $appdata (@appdata) {
: ($name, $value) = split(/=/, $appdata);
: $value =~ tr/+/ /;
: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
: $FORM{$name} = $value;
: }
: [/code]
:
: I've been using this block of code for quite a while to parse data
: coming in from all the forms i've ever used.
:
Yup, and it doesn't parse GET requests, only POST ones. Try something like this:-
[code]
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@appdata = split(/&/, $ENV{'QUERY_STRING'});
} else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@appdata = split(/&/, $buffer);
}
foreach $appdata (@appdata) {
($name, $value) = split(/=/, $appdata);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
[/code]
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
: : : interesting mix of GET and POST going on here. GET is where data
: : : being sent is put in the query string. With a POST the data is
: : : not put in the query string, but sent "seperately". I'm now
: : : guessing $FORM only contains the results of a POST, not a GET.
: : :
: : sorry its taken me a little while to get back and post. Its been
: : crazy at work this week and till I get home I'm fried and don't even
: : turn on the computer.
: :
: Even if you had, you most likely wouldn't have got an answer much more quickly. I've spent the last couple of days being pretty unwell, and have barely touched my computer either. :-(
Sorry you haven't been feeling well. Hope you're feeling better. And thanks, I'll give that a try. I have a feeling it'll work now. I was wondering about this but wasn't sure exactly how to procede.
--
Mark
"If I can't code I'm not going to be a happy camper!"
Mostly. At least, I've been well enough to make it to my lectures today (yes, us folks at Cambridge get 9 AM lectures SIX days a week!)
: And thanks, I'll give that a try. I have a feeling it'll work now. I
: was wondering about this but wasn't sure exactly how to procede.
:
My fingers are crossed. :-)
Jonathan
###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
: Mostly. At least, I've been well enough to make it to my lectures today (yes, us folks at Cambridge get 9 AM lectures SIX days a week!)
:
: : And thanks, I'll give that a try. I have a feeling it'll work now. I
: : was wondering about this but wasn't sure exactly how to procede.
: :
: My fingers are crossed. :-)
:
: Jonathan
grrrrrrrrrrrrrrrr.... now it would appear there's something else has run amuck with this program. at the moment I'm getting a "premature end of script headers" error when the program runs which likely means there's an error somewhere that I've got to find before I can actually see if this form parse change is working. Although I can't imagine why it wouldn't work from the looks of things.
--
Mark
"If I can't code I'm not going to be a happy camper!"