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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.