I am writting a script using DBI::Oracle to insert user account into
database, before inserting I need to verify to make sure userid is not
already existed.  I have script written, ran it but nothing seems happen.
Can someone look into my script and provide me some correction?


Thanks,
David 


****************Script goes below********************

#!/usr/local/bin/perl -w


use CGI qw(param);

use DBI;

 

 

##############################

# Setup Configurable Variables

##############################

$date = `date`;

 

$username = param("username");

$username =~ s/%27|'|"|;|#|$//g;

chomp ($username);

 

$email = param("email");

$email =~ s/%27|'|"|;|#|$//g;

chomp ($email);

 

$phone = param("phone");

$phone =~ s/%27|(|)|'|"|;|#|$//g;

chomp ($phone);

 

$department = param("department");

$department =~ s/%27|'|"|;|#|$//g;

chomp ($department);

 

$ems = param("ems");

$ems = `echo $ems | tr "[a-z]" "[A-Z]"`;

chomp ($ems);

 

$sgx = param("sgx");

$sgx = `echo $sgx | tr "[a-z]" "[A-Z]"`;

chomp ($sgx);

 

$psx = param("psx");

$psx = `echo $psx | tr "[a-z]" "[A-Z]"`;

chomp ($psx);

 

$nfs = param("nfs");

$nfs = `echo $nfs | tr "[a-z]" "[A-Z]"`;

chomp ($nfs);

 

$gsx = param("gsx");

$gsx = `echo $gsx | tr "[a-z]" "[A-Z]"`;

chomp ($gsx);

 

$other = param("other");

$other = `echo $other | tr "[a-z]" "[A-Z]"`;

chomp ($other);

 

$location = param("location");

$location =~ s/%27|'|"|;|#|$//g;

chomp ($location);

 

$reason = param("reason");

$reason =~ s/%27|'|"|;|#|$//g;

chomp ($reason);

 

$manager = param("manager");

#$manager = `echo $manager | tr "[a-z]" "[A-Z]"`;

chomp ($manager);

 

$userid = param("userid");

chomp ($userid);

 

$keyword = param("keyword");

$keyword =~ s/%27|'|"|;|#|$//g;

chomp ($keyword);

 

$comments = param("comments");

$comments =~ s/%27|'|"|;|#|$//g;

chomp ($comments);

 

################################

# Output the HTML content type

################################

print "Content-type: text/html\n\n";

 

 

###############

# SQL 
###############

 

$SQLCHECK="select userid from useraccount where userid = '$userid'";

 

$SQL = "insert into
useraccount(username,email,phone,department,ems,sgx,psx,nfs,
gsx,other,location,reason,manager,userid,keyword,comments)

values

('$username','$email','$phone','$department','$ems','$sgx','$psx','$nfs','$g
sx',
'$other','$location','$reason','$manager','$userid','$keyword','$comments')"
;   
 

$dbh = DBI->connect( "serverdbmachine","user","password","Oracle" );

 

$cursor = $dbh->prepare( "$SQLCHECK" );

 

cursor->execute();

@result = $cursor->fetchrow();

 

   if (@result eq "$userid") {

      print "User $userid already exists\n";

      } else {

        $cursor = $dbh->prepare( "$SQL" );

        $cursor->execute() || die $cursor->errstr;

        print "Your request has been sent.  THANK YOU\n";

        $cursor = $dbh->commit();

 

   }


 

$cursor->finish;

$dbh->disconnect;

Reply via email to