Hi
And thanks again.
Can anyone suggest why the following gives me an error of:
'no comma allowed after filehandle at /cgi-bin/filename line 13'
Line 13 is the print header, start_html( etc etc one
A script which begins in exactly the same way does not do this (and
alos runs fine).
#!/usr/bin/perl -w
#
# test script to query an mysql database via cgi and web interface
# developed as standalone and now for conversion to run as cgi
# - in hashes at the bottom is the functionning standalone version
#
use strict;
use DBI;
use CGI qw(standard);
my ($sql, $dbh, $sth, $field1, $value1, $field2, $value2, @rows, $counter, $q);
print header, start_html("test_query"), h1("test_query");
print p("If you want to query the database please fill in the form
below and press the Query button"), print hr();
$q = CGI -> new();
if (param()) {
$field1 = param ("field1");
$value1 = param ("value1");
$field2 = param ("field2");
$value2 = param ("value2");
print h2("OK so far");
$dbh = DBI -> connect ("DBI:mysql:ami","fgs") || die $DBI::errstr;
$sql = qq{SELECT * FROM testami WHERE $field1 = '$value1' and $field2 = '$value2'};
$sth = $dbh -> prepare($sql);
$sth -> execute();
$counter = 0;
while (@rows = $sth -> fetchrow_array()) {
$counter++;
$dbh -> disconnect();
}
print p("The toal number of matches was \$counter");
}
else {
print hr();
print start_form();
print p("What is the first field ? : ", textfield ("field1"));
print p("WHat is value for field one ? : ", textfield ("value1"));
print p("What is name of field2 ? : ", textfield("field2"));
print p("What is value for field2 ? : ", testfield("value2"));
print p(submit("Query"), reset("Clear"));
print end_form(), hr();
}
print end_html();
#!/usr/bin/perl -w
#
#use strict;
#use DBI;
#my ($sql, $dbh, $sth, $field1, $value1, $field2, $value2, @rows, $counter);
#
#print "Enter the first fieldname (field1) : "; chomp ($field1 = <>);
#print "enter the value for field one (value1) : "; chomp ($value1 = <>);
#print "Enter the second fieldname (field2) : "; chomp ($field2 = <>);
#print "enter the value for field two (value2) : "; chomp ($value2 = <>);
#$dbh = DBI -> connect ("DBI:mysql:ami","fgs") || die $DBI::errstr;
#$sql = qq{SELECT * FROM testami WHERE $field1 = '$value1' and $field2 = '$value2'};
#$sth = $dbh -> prepare($sql);
#$sth -> execute();
#$counter = 0;
#while (@rows = $sth -> fetchrow_array()) {
# $counter++;
# print "@rows\n";
#};
# print "Number of records = $counter\n\n";
#$dbh -> disconnect;