hi,
I have designed a module, which contains a template for insert command.
The code is as under:
I am able to get column names by $var scalar , and all the values in $vals,
but i am getting error while executing the query as under:
DBD::mysql::st execute failed: Unknown column 'pavan' in 'field list' at D:/pavan/Workspace/sample/insert_template .pl line 107.
Use of uninitialized value in string ne at D:/pavan/Workspace/sample/insert_template .pl line 108.
how to correct the mistake?
Thanks & Regards,
Pavan
I have designed a module, which contains a template for insert command.
The code is as under:
Code:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year+=1900; $mon++; my $col_name = "100"; my $ins_name = "pavan"; my $ins_id = 3; my $ins_desc = "hi"; my $createdby = 1; my $modifiedby = 1; my $table_name = Institution; my (@colnames,@values,@exec_arr); my $now='now'; push(@colnames,Institution_Id,Institution_Name,Institution_Desc,Createdby,Createddtm,Modifiedby,Modifieddtm,Customer_Id); my $count = @colnames; push(@values,$ins_id,$ins_name,$ins_desc,$createdby,$now,$modifiedby,$now,100); #print "@colnames"; #my @arr2 = sub1($table_name,@colnames,@values); sub1($table_name,@colnames,@values); sub sub1 { push(my @arr,@_); print "@arr"; my $tab_name = $arr[0]; shift(@arr); print "--------------------------------------- \n"; print "$arr[0]"; print "--------------------------------------- \n"; print "\n<<@arr>>"; print " \n$tab_name \n"; my $count = scalar(@arr); print "<<$count>>> \n"; my $limit = $count/2; $i=0; my $var=''; print "<$limit> \n"; while($i<$limit) { if( ($i) == $limit-1 ) { $var = $var . $arr[$i]; } else { $var = $var . $arr[$i] . ","; } $i++; } print "\n var:::::::$var"; $i=$limit++; my $vals=''; while($i<$count) { if( ($i) == $count-1 ) { $vals = $vals . $arr[$i]; } else { $vals = $vals . $arr[$i] . ","; } $i++; } print "\n vals:::::::$vals \n"; my $sth = $dbh->prepare("insert into $tab_name ($var) values ($vals)"); my $resp = $sth->execute(); if($resp ne '0E0') { print "Successfully inserted"; } }
but i am getting error while executing the query as under:
DBD::mysql::st execute failed: Unknown column 'pavan' in 'field list' at D:/pavan/Workspace/sample/insert_template .pl line 107.
Use of uninitialized value in string ne at D:/pavan/Workspace/sample/insert_template .pl line 108.
how to correct the mistake?
Thanks & Regards,
Pavan
Comment