For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > September 2005 > POST, PARAM & IF STATEMENT









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author POST, PARAM & IF STATEMENT
nat@riverrunsituationist.com

2005-09-16, 6:55 pm

I've been trying to get something like the following to head a larger
perl program:

use CGI qw/:standard -nosticky/;
use CGI::Carp qw/warningsToBrowser fatalsToBrowser/;
$jake = "";
$password = "0";
$jake = param('ape');
print header (-expires => "now");
print qq{<form method = "post" -nosticky><input type="password" name =
"ape" value="" -override <br />
<INPUT TYPE=SUBMIT VALUE="submit">
</form>};
print qq{</body></html>};
if ($jake == 'friend'){print "Ring around the roses"};

the final if print comment "Ring around..." is printed every time
anything is submitted and every time I refresh the page. This
obviously won't work. Can anyone explain why and how to fix it?

wisefamily@integrity.com

2005-09-17, 3:59 am

> if ($jake == 'friend'){print "Ring around the roses"};

I think that should be:
if ($jake eq 'friend'){print "Ring around the roses"};

> the final if print comment "Ring around..." is printed every time
> anything is submitted and every time I refresh the page. This
> obviously won't work. Can anyone explain why and how to fix it?


If you use the "==" operator, both strings are converted to numbers.
If the string has no numeric content, the string is converted to 0.
Since they both are converted to 0, the comparison will always be true
(unless $jake is a non-zero number).

Hope this helps,
David

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com