#!/usr/bin/perl -wT
use strict;
use CGI;
use warnings;
use 5.010;
use utf8;
use DBI;
use Data::Dumper;
use LWP::Simple;
#header
my $query = CGI->new();
warn Dumper($query);
print $query->header( "text/html" ),
$query->start_html(-title => "Query prodotti",
-bgcolor => "#ddffdd"
);
#definition of variables
my $db="prova";
my $host="localhost";
my $user="I-inserted-here-the-user-name";
my $password="I-inserted-here-the-user-pass";
#connect to MySQL database
my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host",
$user,
$password)
or die "Can't connect to database: $DBI::errstr\n";
##assign keyword to a variable
#my $key_id_prod = "key_id_prod";
my $key_nome_prod = "key_nome_prod";
my $key_tipo_prod = "key_tipo_prod";
#prepare the query
my $sql = "INSERT INTO prodotti (nome_prod , tipologia_prod) VALUES (? , ?)" ;
my $sth = $dbh->prepare( $sql);
$sth->bind_param( $key_nome_prod, $key_tipo_prod);
#execute the query
$sth->execute( );
# Retrieve the results of a row of data and print
my ( $id_prod);
$sth->bind_columns ( undef,\$id_prod, \$key_nome_prod, \$key_tipo_prod );
print "La lista aggiornata dei prodotti presenti nel database negozi è:
";
print " ===================================================================
";
while ( $sth->fetch( ) ) {
print "Id del prodotto= $id_prod , il nome del prodotto è $key_nome_prod della tipologia $key_tipo_prod .
";
}
print $query->end_html();
$sth->finish( );
$dbh->disconnect( );
exit;