Good evening to all of you esteemed monks,
I'm new of perl-cgi-mysql-Apache(2) and I'm learning them at same time for my new job.
I prepared these scripts(as exercises)in a database suitable for testing with the intention of create an html form page where a user can insert some data in the prova.prodotti database's table in a safe way by the form and than get a page with the updated list of all products in the table.
LWP was a module that I had to use for this exercise but I don't know how to do this neither without so I'm trying to do it one step at a time(more or less).
The two scripts are:
LWP_Query.cgi
#!/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 => "Inserisci 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::err +str\n"; print <<'HERE'; <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title>Prova input</title> </head> <body bgcolor= #ffddff> <h1 align="center"> Inserisci questo prodotto nel database de +i negozi:</h1> <br><br> <p align="center"> <form action="http://localhost/cgi-b +in/databaseLWP.cgi" method="post"><br> </p> <p align="center"><br> <input type="text" placeholder="Inserisci qui +il nome del prodotto" name="key_nome_prod" size="30" style="height:25 +px;font-size:18pt" maxlength$ <input type="text" placeholder="Inserisci qui +la tipologia del prodotto" name="key_tipo_prod" size="30" style="heig +ht:25px;font-size:18pt"maxle$ <input type="submit" value="Sent" name="invi +a" style="height:35px; width:70px" /> <input type="reset" value="Reset" style="hei +ght:35px; width:70px" /> </p> </body> </html> HERE print $query->end_html(); $dbh->disconnect( ); exit;
databaseLWP.cgi
#!/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::err +str\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 "<i>La lista aggiornata dei prodotti presenti nel database negoz +i è:</i> <br><br>"; print " ============================================================== +===== <br><br>"; while ( $sth->fetch( ) ) { print "<i>Id del prodotto=</i><b> $id_prod </b>,<i> il nome del +prodotto è</i><b> $key_nome_prod </b> della tipologia $key_tipo_prod +.<br>"; } print $query->end_html(); $sth->finish( ); $dbh->disconnect( ); exit;
eirinyalaura@Laura://var/log$ sudo tail -f /var/log/apache2/error.log [sudo] password for eirinyalaura: [Thu Dec 10 XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: DBD::mysql: +:st bind_columns failed: Statement has no result columns to bind (per +haps you need to successfully call execute first, or again) at /usr/l +ib/cgi-bin/databaseLWP.cgi line 54., referer: http://localhost/cgi-bi +n/LWP_Query.cgi [Thu Dec 10 XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: DBD::mysql: +:st fetch failed: fetch() without execute() at /usr/lib/cgi-bin/datab +aseLWP.cgi line 59., referer: http://localhost/cgi-bin/LWP_Query.cgi [XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: $VAR1 = bless( { [XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: '.par +ameters' => [], [Thu Dec 10 XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: + '.fieldnames' => {}, [Thu Dec 10 XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: + 'use_tempfile' => 1, [Thu Dec 10 XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: + '.charset' => 'ISO-8859-1', [Thu Dec 10 XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: + 'escape' => 1, [Thu Dec 10 XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: + 'param' => {} [Thu Dec 10 XXX] [cgi:error] [pid XXX] [client ::XXX] XXX: + }, 'CGI' );
In reply to [SOLVED]Bind and fetch fails by Eirinya
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |