I am trying to integrate CGI with DBI . I am taking the results from the cgi and adding it on to the DBI . But cgi script not able connect to the DBI . Script is mentioned below . The script is not able to connect with DBI as its failing at connection phase .
use CGI qw/:standard/;
use Apache::DBI;
use DBI ;
my $driver = "mysql";
my $database = "testdb";
my $dsn = "DBI:mysql:testdb";
my $userid = "testuser";
my $password = "test123";
print
header,
start_html('Simple Script'),
h1('Simple Script'),
start_form,
"What's your First name? ",textfield('First name'),p,
"What's your Last name? ",textfield('Last name'),p,
"What's your Age? ",textfield('Age'),p,
"What's your Income? ",textfield('Income'),p,
popup_menu(-name=>'Sex',
-values=>['Male','Female']),p,
submit,
end_form,
hr,"\n";
if (param) {
my $FIRST_NAME=em(param('First name')) ;
my $LAST_NAME=em(param('Last name')) ;
my $AGE=em(param('Age')) ;
my $INCOME=em(param('Income')) ;
my $SEX =em(param('Sex')) ;
print
$FIRST_NAME ,p,
$LAST_NAME,p,
$SEX,p,
$AGE,p,
$dsn,p
$INCOME ;
my $dbh = DBI->connect($dsn,"root","" ) or die "Can't connect: ",$DBI::errstr;
my $stmt ;
my $sql = "INSERT INTO TEST_TABLE (FIRST_NAME, LAST_NAME, SEX, AGE, INCOME ) values (?,?, ?, ?, ?)";
my $stmt = $dbh->prepare($sql);
$stmt->execute($FIRST_NAME,$LAST_NAME, $SEX, $AGE, $INCOME) or die $DBI::errstr;
}
print end_html;