MySQL Forums
Forum List  »  Perl

Re: fetch a problem to insert values in perl programming
Posted by: arupratan biswas
Date: May 18, 2005 10:46PM

when i execute my programm linux then give error just like that
DBD::mysql::st execute failed:Column 'emp_id' can not be null at line 44 and
could not execute:Column 'emp_id' can not be null at line 44.
and when i give input through my internet browser in every field then give:" internal server error".
programm for html(that work correctly) like that :
#!/usr/bin/perl

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

print "<html>";
print "<body bgcolor='#abcdef'>";
print "<form method='post' action='test13.pl'>";
print "<pre>";
print "<p> Employee ID: ";
print "<input type='text' name='emp_id'></p><br>";

print "<p> Employee Name: ";
print "<input type='text' name='emp_id'></p><br>";
print "<p> Employee Address: ";
print "<input type='text' name='emp_add'></p><br>";
print "<p> City Name: ";
print "<input type='text' name='city'></p><br>";
print "<p> Date Of Birth: ";
print "<input type='text' name='dob'></p><br>";
print "<p> Phone No: ";
print "<input type='text' name='phone'></p><br>";
print "<p> Employee Photo: ";
print "<input type='file' name='photo'></p><br>";
print "<center><input type='submit' value='submit'></center><br>";
print "</pre>";
print "</form>";
print "</body>";
print "</html>";
------------------------------------------------------------------------

and scripting side programm is as that:
#!/usr/bin/perl

use DBI;
use CGI;
$q=new CGI;
#$var=$q->param('cv');
$emp_id=$q->param('emp_id');
$emp_name=$q->param('emp_name');
$emp_add=$q->param('emp_add');
$city=$q->param('city');
$zip_code=$q->param('zip_code');
$dob=$q->param('dob');
$phone=$q->param('phone');
$photo=$q->param('photo');

$upload_dir="/httpd/html/guest4/load";
$filename = $q->param("photo");
$photo =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $q->upload("photo");


open UPLOADFILE, ">$upload_dir/$photo";

binmode UPLOADFILE;

while ( <$upload_filehandle> )
{
print UPLOADFILE;
}

close UPLOADFILE;

$dbh = DBI->connect("dbi:mysql:test:192.168.0.95","bobby","bobby");

my $sqlstatement = qq{INSERT INTO new_user
(emp_id, emp_name, emp_add, city, zip_code, dob, phone, photo)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)
};

#$sqlstatement="INSERT INTO new_user (emp_id,emp_name,emp_add,city,zip_code,dob,phone,photo) VALUES($emp_id,'$emp_name','$emp_add','$city',$zip_code,'$dob','$phone','$photo')";

my $sth = $dbh->prepare($sqlstatement) or die "Could not prepare statement: $DBI::errstr";

$sth->execute($emp_id, $emp_name, $emp_add, $city, $zip_code, $dob, $phone, $photo)
or die "Could not execute: $DBI::errstr";


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

print <<ENDHTML;

<html>
<head>
<title>Update details</title>
</head>
<body>
<h1><font color = "#008000"> Successfully Inserted</font></h1>
</body>
</html>
ENDHTML


'emp_id' is primary key in my database.
felix plz help.
arup ratan

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.