but I also changed the ? with directly name of the variables because if I didn't it the query inserted only ? instead of values. With these modifications the script now puts the value in the database but without enough security in my opinion, what do you suggest?

Don't put quotes around the question marks. If you do they will be treated as string literals. Here's some sample code to get you started:

my $sql = 'INSERT INTO prodotti (nome_prod , tipologia_prod) VALUES (? +, ?)' ; my $sth = $dbh->prepare ($sql); my $res = $sth->execute ($key_nome_prod, $key_tipo_prod); die ("Result is $res instead of 1: " . $sth->errstr) unless (defined $ +res && $res == 1);

In order this:

  1. Sets up the SQL statement with 2 placeholders for the data values
  2. Prepares the SQL statement into a statement handle $sth
  3. Executes one insert with the two variables as bound arguments and captures the result
  4. Throws an exception if the result is not as expected

Constructing the query this way with the bind parameters means that the data from the untrusted source is handled securely by the driver and eliminates the possibility of SQL injection from this direction.


In reply to Re^3: Bind and fetch fails by hippo
in thread [SOLVED]Bind and fetch fails by Eirinya

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.