hello all,
#!/usr/bin/perl
use DBI;
sub insert {
my ($insert_sql,$sth);
my $nik=12345678; # 8 digit
my $password=12345678; # 8 digit
my $scode=2; # 1 digit
#configuration database
$database = "user";
$dbuser = "hendra";
$dbpasswd = "hendra123";
$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,password,scode) values (?,?,?)};
$sth = $dbh->prepare($insert_sql) || die "prepare: $insert_sql: $DBI::errstr";
$sth->execute($nik,$password,$scode) || die "Unable to execute query:
$dbh->errstr\n";
$sth->finish;
$dbh->disconnect;
}
print "INPUT : ";
while ($input=<>) { # Read the user input
# format: nik[space]password[space]scode -> use pattern matching
if ($input =~/12345678 12345678 2/){
insert();
} else {
print "Cannot Insert";
}#end if
print "INPUT : ";
}#end while
==================================
that's scripts work and data can insert into mysql.
but i can't insert any data to mysql if i change the variabel on top with this :
my $nik = @_; # 8 digit
my $password = @_; # 8 digit
my $scode = @_; # 1 digit
and also i change :
# format: nik[space]password[space]scode -> use pattern matching
if ($input =~/(\d{8})(\s{1})(\d{8})(\s{1})(\d{1})/){
.................
if i execute the scripts with another input, data will insert into mysql what i type
in shell but data incorrect and on tabel the value is 0 for each fields.
the question is how to insert data into mysql with another input from shell with
pattern matching.
regards,
hendra kusnandar
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam