Nik has asked for the wisdom of the Perl Monks concerning the following question:

In the top of my games.pl script i have
my $gamename = param('gamename');
and
print start_form(-action=>'games.pl'); print table( {class=>'games'} ); while( $row = $sth->fetchrow_hashref ) { print Tr( td( {-width=>'20%'}, submit( $row->{gamename} )) +, td( {-width=>'75%'}, $row->{gamedesc} ), td( {-width=>'5%'}, $row->{gamecounter} ) ); } print end_table; print end_form;
This is where the submit button is created and this is where i check if the user click on a game
if( param('gamename') )
but it never returns true! Do you think there is a confilct with the gamesnname as i have it in the submit button and expect the user to click on the desired game to download by passign it as a parameter to the script?

20050516 Edit by castaway: Changed title from 'Maybe this causes the problem?'

Replies are listed 'Best First'.
Re: Determining which CGI submit() button was pressed
by jasonk (Parson) on May 12, 2005 at 15:46 UTC

    Your submit button is not named 'gamename', it is named whatever $row->{gamename} contains. Perhaps you wanted submit(-name => 'gamename', -value => $row->{gamename})


    We're not surrounded, we're in a target-rich environment!
      Yes thats true but i tried it as you suggest and it still does not work: Here take a better picture of it because the problem maybe lurks someplace else:
      #=======================LOADING THE .TXT TO THE DATABASE============== +========== my $replace = $dbh->prepare( "REPLACE INTO games (gamename, gamedesc, +gamecounter) VALUES (?, ?, ?)" ); open (FILE, "<../data/games/descriptions.txt") or die $!; while (<FILE>) { chomp; if (length) { $replace->execute( split(/\t/, $_, 2), 0) or print $dbh->errst +r; } } close (FILE); #=============================SHOW THE GAMES TABLE==================== +========== print span( {class=>'lime'}, "Από εδώ μπορείς να κατεβάσεις ωραία α +πλά παιχνίδια που έχω επιλέξει!" ), br; print span( {class=>'yellow'}, "Μπορείς να επικοινωνήσεις μαζί μου στ +ο hackeras\@gmail.com" ), br() x 2; $sth = $dbh->prepare( "SELECT * FROM games" ); $sth->execute; print start_form(-action=>'games.pl'); print table( {class=>'games'} ); while( $row = $sth->fetchrow_hashref ) { print Tr( td( {-width=>'20%'}, submit( -name=>'gamename', +-value=>$row->{gamename} )), td( {-width=>'75%'}, $row->{gamedesc} ), td( {-width=>'5%'}, $row->{gamecounter} ) ); } print end_table; print end_form; print br; unless ( param() ) { print p( {-align=>'center'}, a( {href=>'index.pl'}, img {src=>'. +./data/images/back.gif'} )); } #==============================GIVE USER THE GAME===================== +========== if( param('gamename') ) { $dbh->do( "UPDATE games SET gamecounter=gamecounter+1 WHERE gamena +me='$gamename'" ); $dbh->do( "UPDATE guestlog SET passage='$gamename' WHERE host='$ho +st'" ); $sth = $dbh->prepare( "SELECT * FROM games WHERE gamename=?" ); $sth->execute( $gamename ); $row = $sth->fetchrow_hashref; print span( {class=>'lime'}, "Είσαι ο $row->{gamecounter} ος πο +υ κατεβάζει το $row->{gamename} !!" ), br; print span( {class=>'yellow'}, "Ελπίζω να σου αρέσει και να σου φ +ανεί χρήσιμο!" ); print p( {-align=>'center'}, a( {href=>'index.pl'}, img {src=>'. +./data/images/back.gif'} )); print "<script language='Javascript'>location.href=/data/games/$ga +mename.rar</script>"; }
Re: Determining which CGI submit() button was pressed
by davido (Cardinal) on May 12, 2005 at 15:56 UTC

    As a debugging tip, you might try this, to see what parameters you actually have, and what their values are:

    At the top of your script, add one more use: use Data::Dumper;. Then, right after your print end_form; statement, add this line:

    print "<pre> "; print Dumper Vars(); print " </pre>"

    Now run the script and see what you get. It will dump all parameters as key/value pairs to the screen. You can also run it from the commandline. In fact, using CGI is really convenient; it lets you run scripts from the command line where you simply add the parameter list to the command line. For example, your script is named "games.pl"... so run it like this and see what output you get:

    perl games.pl "gamename = test"

    ...that's assuming an MSDOS type OS. Change the quotes to work with whatever flavor of operating system you're on. The point is you'll see pretty clearly what the error messages (if any) are, and what else is going on. And above all, make sure you've got warnings enabled. That can often tell you what's wrong too.


    Dave

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Determining which CGI submit() button was pressed
by polettix (Vicar) on May 12, 2005 at 15:59 UTC
    You maybe also want to substitute:
    print table( {class=>'games'} );
    with
    print start_table( {class=>'games'} );
    even if it isn't related to your specific question.

    Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

    Don't fool yourself.
    A reply falls below the community's threshold of quality. You may see it by logging in.