in reply to Re^2: problem checking availability
in thread problem checking availability

Eliminating just one error isn't enough for software to work correctly. You need to eliminate all of them, preferably without introducing new ones. In your recent example I see a number of errors which you might have spotted if you had used use strict:

  1. You prepare a statement to $CHECK_PHONE and then execute it on $CHECK_EMAIL with the phone number as parameter. Calling fetchrow_arrayref on a statement which hasn't been executed will not return an array reference.
  2. Next you test for $E->[0] but $E has never been set.
  3. In both error branches you set the variable $error_phone.

You should really try to provide a complete example, run it on your database and then post it, together with the result. We are still at a level where I just need to look at the code to spot several - new - problems.

Replies are listed 'Best First'.
Re^4: problem checking availability
by bigup401 (Pilgrim) on Sep 04, 2018 at 08:23 UTC

    sorry its $check_phone

    am trying to pest a sample thing. how can it get solved

      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

        thanks for the sample. but couldn't work for me. the fact is that my code was working the only problem was termating the script to not insert data if id_number and phone exits. bt finally i figured it out. and worked