Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Inserting Select Array Material to MySql

by poj (Abbot)
on Sep 11, 2015 at 07:44 UTC ( [id://1141645]=note: print w/replies, xml ) Need Help??


in reply to Inserting Select Array Material to MySql

Assuming uid is AUTO_INCREMENT try

my $sql = "INSERT INTO $table (uid,mid,qty) VALUES (NULL,?,?)"; my $sth = $dbh->prepare($sql); for (keys %medals){ if ( $medals{$_} > 0 ){ $sth->execute ($_ ,$medals{$_}); } }

LAST_INSERT_ID() will work for the first insert of the session because it will be 0, but subsequent inserts will fail as you try to enter another record with the same uid as the previous one.

poj

Replies are listed 'Best First'.
Re^2: Inserting Select Array Material to MySql
by typomaniac (Novice) on Sep 12, 2015 at 04:43 UTC
    Thanx, sorry for the screwball coding--fixed now. The LAST_INSERT_ID(), was actually tracking from one insert statement to the next. Anyway, on the other issue, I will have to re-post that one although I did find that the wrong column name was listed. The main problem I'm having is to get checkboxes to insert into mysql---if there were 5 boxes and 3 were clicked only one of them shows up in the db. As said before I will post at a later time when I get the xampp server software all working again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1141645]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found