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 :

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

print "<html>";
print "<body bgcolor='#abcdef'>";
print "<form method='post' action=''>";
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:

use DBI;
use CGI;
$q=new CGI;

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

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


while ( <$upload_filehandle> )


$dbh = DBI->connect("dbi:mysql:test:","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;

<title>Update details</title>
<h1><font color = "#008000"> Successfully Inserted</font></h1>

'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.