Ok, I think the error comes because you have forgot to define the columns ar your MySQL syntax:
my $sth = $dbh->prepare(qq{INSERT INTO `tutpoint_tbl` (`column-1`,`col +umn-2`,`column-3`) VALUES (?,?,?)});
Change "column-1,column-2,column-3" with your column names, and also at the execute part:
$sth->execute("$tut_id","$tut_title","$tut_author") || die $DBI::errst +r;
I think it should work now. It would be good to load also the warnings it will help you with decoding errors:
use warnings;
Update:
I am sorry I did not explain why I reccomend using the following syntax. We use backticks (`) when you to insert a name that might be reserved for enclosing identifiers such as table and column names. MySQL 9.3 Reserved Words, ofcourse if you are not using reserved word you do not need to use backticks but I have preference to use them to help better when I am decoding my code and understand the process step by step.
The double quotes (") we use them because you are executing a MySQL command through strings $string.
Finalyzing, since you are using strings for denoting $username, $password etc. when you loging to mysql, I would use it also for naming the table e.g. `$tutpoint_tbl` and in any point that the name can be changed.
By doing so, you have a more generic code and having a configutation file you can easilly modify the names. In any other case if you want to use another table you will have to change the name on the INSERT function. Well it does not seem so importand but imagine a greater picture where you have UPDATE statements also that are using the same table name and for some reason you decided to change the table and dbase name you have to go and change the values manually in several points when you can just change one.
I hope my explanation makes sense and it is not confusing, in any case please do not hesitate to ask me if you do not understand what I am saying.
In reply to Re: Not able to insert data in mysql
by thanos1983
in thread Not able to insert data in mysql
by ashishg0310
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |