$sth = $dbh->prepare(q{SELECT oid from items where orderid = ?}) || die $dbh->errstr; $sth->execute($orderid) || die $dbh->errstr; my @oids; my $oid; $sth->bind_columns(\$oid); # Binds each column to $oid, through reference my $i; my $max; for ($i = 0; $sth->fetch; $i++) { # The fetch updates $oid to the next one. $oids[$i] = $oid; $max = $i; } for ($i = 0; $i <= $max; $i++) { my $price = $q->param("item_" . $oids[$i] . "_price"); # Gets price from cgi my $curoid = $oids[$i]; # unecessary...? $sth = $dbh->prepare(q{UPDATE items set price = (?) WHERE oid = (?)}) || die $dbh->errstr; $sth->execute($price, $curoid) || die $dbh->errstr; }