hai patty, i don't understand your opinion but thank's
for your response.
to correct my script where i put the select count(*)
on my scripts. I have tried every way
possible and I can think of and I cannot get it to
work at all.
may be you can correct my scripts, sorry i'am still
beginner with perl.
for mike thank's for your response. I want handle
duplicate data if input source are same and will show
message on shell
"sorry, same data cannot insert again" and data will
not insert into database.
i have search with google to correct the scripts, but
i can found the solution...may be everyone have same
case with me to solve the problem.
the scripts are :
#!/usr/bin/perl
use DBI;
sub insert_user {
my ($nim, $nama, $password) = @_;
my ($insert_sql,$sth);
$database = "practice_perl";
$dbuser = "hendra";
$dbpasswd = "hendra";
$dbhost = "localhost";
$dsn = "DBI:mysql:database=$database;host=$dbhost";
$dbh = DBI->connect($dsn,$dbuser,$dbpasswd) || die
$DBI::errstr;
$insert_sql = qq {insert into user
(nik,name,password) values ('$nik', '$name',
'$password')};
$sth = $dbh->prepare($insert_sql) || die "prepare:
$insert_sql: $DBI::errstr";
$sth->execute || die "Unable to execute query:
$dbh->errstr\n";
$sth->finish;
$dbh->disconnect;
}#end insert_user
sub insert_log {
my ($input) = @_;
my ($insert_sql_log);
$database = "practice_perl";
$dbuser = "hendra";
$dbpasswd = "hendra";
$dbhost = "localhost";
$dsn = "DBI:mysql:database=$database;host=$dbhost";
$dbh = DBI->connect($dsn,$dbuser,$dbpasswd) || die
$DBI::errstr;
$insert_sql_log = "insert into log values
('',".$dbh->quote($input).")";
$dbh->do($insert_sql_log) || die ($dbh->errstr);
return $dbh->{'mysql_insertid'};
$dbh->disconnect;
}#end insert_log
print "INPUT : ";
while ($input = <>) {
#format insert : nik,name,password
if($input =~/^(\d{8}),(.*),(\w{6})$/i){
insert_user($1,$2,$3);
}else{
insert_log($input);
print "Wrong Format";
}#end if
print "\nINPUT : ";
}#end while
Hendra Kusnandar
__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/