how can it get solved

Post a complete runnable example like haj suggested. For example

#!perl use strict; use warnings; use DBI; my $DBH = get_dbh(); # connect to db #$DBH->do('DELETE FROM tbl1'); # insert records (ID_NUMBER,PHONE) into tbl1 # Tests print insert(1,'00001'); print insert(2,'00002'); print insert(2,'00002'); print insert(2,'00003'); print insert(3,'00002'); print insert(2,undef); print insert(3,undef); print insert(undef,'00002'); print insert(undef,'00003'); print insert(undef,undef); sub insert { my ($ID_NUMBER,$PHONE) = @_; my @error = (); if ($PHONE) { my $SQL = 'SELECT COUNT(*) FROM tbl1 WHERE PHONE = ?'; my ($count) = $DBH->selectrow_array($SQL,undef,$PHONE); push @error,"PHONE exists ($PHONE)" if $count; } else { push @error,"PHONE blank"; } if ($ID_NUMBER){ my $SQL = 'SELECT COUNT(*) FROM tbl1 WHERE ID_NUMBER = ?'; my ($count) = $DBH->selectrow_array($SQL,undef,$ID_NUMBER); push @error,"ID_NUMBER exists ($ID_NUMBER)" if $count; } else { push @error,"ID_NUMBER blank"; } if (@error){ return "Errors : @error\n" } else { my $SQL = 'INSERT INTO tbl1(PHONE, ID_NUMBER) VALUES(?,?)'; my $count = $DBH->do($SQL,undef,$PHONE, $ID_NUMBER); return "$count record inserted ($PHONE,$ID_NUMBER)\n"; } } sub get_dbh{ my $database = "test"; my $user = ""; my $pw = ""; my $dsn = "dbi:mysql:$database:localhost:3306"; my $dbh = DBI->connect($dsn, $user, $pw, { RaiseError=>1, AutoCommit=>1 } ); return $dbh; }
poj

In reply to Re^5: problem checking availability by poj
in thread problem checking availability by bigup401

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.