Gossamer Forum
Home : General : Perl Programming :

No variables and going to wrong place.

Quote Reply
No variables and going to wrong place.
Is there something I have missed out here as now the HTML bit works and the DBI bit works but not together. The Goldfish page loads when I am asking for DOG! I dont get any error messages. I have tried adding

#!c:\perl\bin\perl.exe
use CGI ":standard";
use DBI;
my $IN = new CGI;
my $choice = $IN->param("choice");

no avial I am putting this togeter bit by bit and want to only access the database once depending on what variable is sent from the previous page, This is what $choice is and will be Dog Cat or Goldfish.

Any more ideas please I am new at this! Chris





#!c:\perl\bin\perl.exe
use CGI ":standard";
$Dog=param("Dog");
$Cat=param("Cat");
$Goldfish=param("Goldfish");
if
($choice eq $Dog)
{
use DBI;
my $DBH = DBI->connect("DBI:mysql:Guide");
my $sth = $DBH->prepare( "SELECT Name FROM Dog" );
$sth->execute();
my $array_ref = $sth->fetchall_arrayref();
foreach my $row (@$array_ref)
{
my ( $Name,) = @$row;
print "\t";
}
$sth->finish();
$DBH->disconnect();

print "content-type:text/html\n\n";
print <<E_O_F;

<HTML>
<HEAD><TITLE>Dog</TITLE>
<BASEFONT FACE="Arial Black">
</HEAD>
<BODY>
<TABLE BORDER="0" ALIGN="center" WIDTH="75%" Height="75%">
<TBODY>
<TR><TD COLSPAN="100%" align="center"><H2>Dog:</H2></TD></TR>
</TBODY>
</TABLE>
</BODY>
</HTML>

E_O_F

}
elsif
($choice eq $Cat)
{
print "content-type:text/html\n\n";
print <<E_O_F;

<HTML>
<HEAD><TITLE>Cat</TITLE>
<BASEFONT FACE="Arial Black">
</HEAD>
<BODY>
<TABLE BORDER="0" ALIGN="center" WIDTH="100%" Height="100%">
<TBODY>
<TR><TD COLSPAN="100%" align="center"><H2>Cat:</H2></TD></TR>
</TBODY>
</TABLE>
</BODY>
</HTML>

E_O_F

}
else
{
print "content-type: text/html\n\n";
print <<E_O_F;

<HTML>
<HEAD><TITLE>Goldfish</TITLE>
<BASEFONT FACE="Arial Black">
</HEAD>
<BODY>
<TABLE BORDER="0" ALIGN="center" WIDTH="100%" Height="100%">
<TBODY>
<TR><TD COLSPAN="100%" align="center"><H2>Goldfish</H2></TD></TR>
</TBODY>
</TABLE>
</BODY>
</HTML>

E_O_F

}
Quote Reply
Re: [Silver Machine] No variables and going to wrong place. In reply to
for the goldfish page to load, the value you are testing the input against must be empty or not matching. for example, when you tried setting $choice to $in->param("choice"), you might have been testing $choice against $Dog, which wouldn't have worked unless your query string was "?choice=Dog&Dog=Dog" or you manually set $Dog to "Dog". Also remember case counts.

how about doing something like:

Code:
my $choice = param("choice");
if ($choice =~ /^Dog$/) {}

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] No variables and going to wrong place. In reply to
Thanks that bit worked great and I have moved on a bit and it will now go to the right page but, the variables won't load! The piece of perl, use DBI; up to $DBH->disconnect(); works perfectly in command prompt and gives me my list of names. But put together it gives me this:

[Thu Jan 15 09:39:57 2004] [error] [client 127.0.0.1] malformed header from script. Bad header= Cindy: choice.pl

Cindy is the first name in the list of 12 at the moment. choice.pl is the name of my program and the name of my incoming variable. I don't understand at all what is happening here any ideas please? Chris

#!c:\perl\bin\perl.exe
use CGI ":standard";
my $choice = param("choice");
my $Dog=param("Dog");
my $Cat=param("Cat");
my $Goldfish=param("Goldfish");
if ($choice =~ /^Dog$/)
{
use DBI;
my $DBH = DBI->connect("DBI:mysql:Guide");
my $sth = $DBH->prepare("SELECT Name FROM Dog");
$sth->execute();
my $array_ref = $sth->fetchall_arrayref();
foreach my $row (@$array_ref)
{
my ($Name) = @$row;
print "\t $Name\n";
}
$sth->finish();
$DBH->disconnect();

print "content-type:text/html\n\n";
print <<E_O_F;
<HTML>
<HEAD><TITLE>Dog </TITLE>
<BASEFONT FACE="Comic Sans MS, fantasy">
</HEAD>
<BODY BGCOLOR = "99CCFF" TEXT="330066" SIZE="5">
<TABLE BORDER="0" ALIGN="center" WIDTH="75%" Height="75%">
<TBODY>
<TR><TD COLSPAN="100%" align="center"><H2>Dog:</H2></TD></TR>
<TR><TD>
The Dog names are:$Name
<TR></TD>
</TBODY>
</TABLE>
</BODY>
</HTML>
E_O_F

Last edited by:

Silver Machine: Jan 15, 2004, 2:05 AM