in reply to Re^3: inserting and showing data from an MS Access database
in thread inserting and showing data from an MS Access database

Thanks for the replies, gentlemen. Now I've pretty much mangled the code but it almost works. The only problem is that the insert statement is inserting a blank row each time with no data in each column. The insert code i'm using is:
my $sth_ins = $dbh->prepare("INSERT INTO users (firstname, lastname, s +tate, country) VALUES (?, ?, ? ,?)") or die "Couldn't insert the data +"; $sth_ins->execute($FORM{firstname}, $FORM{lastname}, $FORM{state}, $FO +RM{country});
I was talking about this problem with a friend of mine who is vaguely familiar with Perl and he mentioned that $FORM{value} was the only way to retrieve the data from
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; }
Is there another way to do it or am I just overlooking something the way it is now?

Replies are listed 'Best First'.
Re^5: inserting and showing data from an MS Access database
by davidrw (Prior) on Apr 12, 2006 at 12:51 UTC
    if the row is blank, then i suspect that %FORM is empty/bad .. to verify, do:
    use Data::Dumper; print Dumper \%FORM;
    But yeah, don't parse the data yourself to begin with -- use CGI:
    use CGI qw/:standard/; $sth_ins->execute( param('firstname'), param('lastname'), param('state +'), param('country') );
      Hi, when I used
      use Daga::Dumper; pring Dumper \%FORM;
      It printed $VAR1 = {}; so I guess that means %FORM is empty as you said. I'm off now to see what I can do about this.
        Oops, I mean Data::Dumper, not Daga::Dumper Also, don't I need to change the
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; }
        bit at the top to use
        $sth_ins->execute( param('firstname'), param('lastname'), param('state +'), param('country') );
        I seem to remember getting errors without adding something else.
        my $name = $query->param($FORM{name});
        or something like that. I may be wrong about that though.