in reply to Re^2: Bind and fetch fails
in thread [SOLVED]Bind and fetch fails

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.