if( $update eq 1) { my $sth= $dbh->prepare("select ip_start, ip_end from ip_range where subscription_no =?"); $sth->execute($subno); my @row; while (@row = $sth->fetchrow_array()) { my($start, $stop)= @row ; $startId=$start; $start=~ s/\.//gi; $stop=~ s/\.//gi; if (($begin1 >= $start) && ($end1 =< $stop)) { $ipFlag=1; } } $sth->finish(); } else { ### insert into table, the fresh data. $host="you"; my $sth = $dbh->prepare("insert into ip_range(subscription_no, ip_start, ip_end, hostname, creator, creationdate) values(?,?,?,?,?,now())"); $sth->execute($subno, $begin, $end, $host, $creator); $sth->finish(); } # update only Creator since ip already exist. if( $ipFlag eq 1) { my $sth= $dbh->prepare("update ip_range set hostname=?, creator=? where subscription_no =?"); $sth->execute($host, $creator, $subno); $sth->finish(); } ### insert into table, the fresh data. else { $host="me"; my $sth = $dbh->prepare("insert into ip_range(subscription_no, ip_start, ip_end, hostname, creator, creationdate) values(?,?,?,?,?,now())"); $sth->execute($subno, $begin, $end, $host, $creator); $sth->finish(); } $dbh->disconnect();