typomaniac has asked for the wisdom of the Perl Monks concerning the following question:
I have a database where, upon submitting a form, some tables are supposed to be able to recieve multiple rows, depending on the user input. For example:
my $med1="Award Number 1"; my $med2="Award Number 2"; my $med3="Award Number 3"; my %medals=( "$med1"=>"$me1", "$med2"=>"$me2", "$med3"=>"$me3", my $table="table"; my $state="INSERT INTO ".$table." (uid,mid,qty) VALUES (LAST_INSERT_ID +(),?,?)"; foreach (keys%medals){ if($medals{$_}>0){ my $sth=$dbh->prepare($state); $sth->execute ($_ ,$medals{$_}); } }
This comes from a bunch of text inputs put into a hash so as to get the name of an award and how many times the award was given. This worked all well and fine but when I tried to use the same code with a different table name and column names it wouldn't work. I'm trying to insert rows from checkboxes using a simple array, which would input rows depending on which boxes met a certain condition but it is only inserting one line of the array which met the conditions. I have searched high and low for information on using perl/cgi to input information put into an array and have basically come up with nothing that works.
Is there something I'm missing here(or, I should say what is it I'm missig) when it comes to doing this. I'm basically down to sets of checkboxes and need to enter them (as many as are checked) into mysql table rows.If I could get the checked box info to insert I would be good to go.
Also, if it makes any difference at all--this is being done using xampp
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inserting Select Array Material to MySql
by 1nickt (Canon) on Sep 11, 2015 at 03:47 UTC | |
|
Re: Inserting Select Array Material to MySql
by poj (Abbot) on Sep 11, 2015 at 07:44 UTC | |
by typomaniac (Novice) on Sep 12, 2015 at 04:43 UTC |