Link to home
Start Free TrialLog in
Avatar of henrycrinkle34
henrycrinkle34

asked on

Simple CGI (perl) form processing script

This script inserts values from an html form into a database.  The problem is that I want it to fail if the $number value already exists in the database.  Is there a simple way of achieving this? Is this even the right area to ask this question?



#!/usr/bin/perl -w
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use DBI;
$ENV{"ORACLE_HOME"} = "/home/oracle/product/9.2.0";
print "Content-type: text/html\n\n";
$dbh = DBI->connect('dbi:Oracle:', q{gavin/a32182302@(DESCRIPTION=
  (ADDRESS=(PROTOCOL=TCP)(HOST= info200.infc.ulst.ac.uk)(PORT=1521))
  (CONNECT_DATA=(SID=ORCL)))}, "") or die "Bad connect";
my $name=param('EName');
my $number=param('ENumber');
my $salary=param('SalaryInfo');
my $job=param('jobType');
print "Inserting ...Ename=$name,Enumber=$number,SalaryInfo=$salary, Job=$job\n";  
my $sql =qq{insert into emp(empno,ename,sal,job) values(?,?,?,?)};
my $sth=$dbh->prepare($sql);
$sth->execute($number,$name,$salary,$job) or die $DBI::errstr;
print "</br>Insert Complete\n";
$dbh->disconnect;
ASKER CERTIFIED SOLUTION
Avatar of Itatsumaki
Itatsumaki

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial