Hi,
I have a strange problem.
I need to insert an ip address entered (entered for updation by existing users)if it does not already exist in database and
update the creator(just a REMOTE_USER field) if the ip given is a sub set of existing entries in database.
And if the customer is brand new person.. a new entry in a database.
Now My problem is with this code For a brand new user, two entries show up.
Also updation is all wrong all the time new entry is done.
update=1 if already a user else its 0;
$begin1 and $end are entries made by user a pure integer format without any '.' like 127001 for 127.0.0.1
Please help me!
if( $update eq 1)
{
my $sth= $dbh->prepare("select ip_start, ip_end from ip_range wher
+e 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();
Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.