Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Perl Database Connectivity Problem

Avatar of tristatefab
tristatefab asked on
Web Languages and Standards
5 Comments1 Solution454 ViewsLast Modified:
Hello Everyone,

I am getting the following errors when I try to run my Perl script... I am trying to pull data from an access database table.. here are the error messages immediately followed by the script code:

[Sat Dec 09 22:34:20 2006] [error] [client 127.0.0.1] DBD::ODBC initialisation failed: Can't locate object method "driver" via package "DBD::ODBC" at C:/Perl/site/lib/DBI.pm line 770., referer: http://localhost/inventory.html
[Sat Dec 09 22:34:20 2006] [error] [client 127.0.0.1] , referer: http://localhost/inventory.html
[Sat Dec 09 22:34:20 2006] [error] [client 127.0.0.1] Perhaps the capitalisation of DBD 'ODBC' isn't right. at C:/Program Files/Apache Group/Apache2/cgi-bin/productdetail.pl line 36, referer: http://localhost/inventory.html



PERL CODE

#!/Perl/bin/perl
# Program to read information sent to the server
# from the form in the contact_list.xhtml document.

use CGI qw( :standard );
# @TODO add dbi inclusion here
use DBI;



$dtd = "-//W3C//DTD XHTML 1.0 Transitional//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";

print( header() );
print( start_html( { dtd    => $dtd,
                     title  => "Product Detail",
                 script => [
                                 { -language => 'JavaScript',
                                   -src      => '/validationFunctions.js'
                                 },
                         getClientValidationScripts()
                         ],
                 style  => {-verbatim => '@import url("/EducateComp.css");',
                                -src      => '/EducateComp.css' } } ) );

print( "<b>Product Detail</b>" );
print( start_form( -id       => "inventoryDetailOrder",
               -action   => "/cgi-bin/acceptorder.pl",
               -onSubmit => "validateForm()" ) );
print( "<table>" );

#open connection to Access database
#no passwords on our database
# @TODO do DBI->connect statement here
#$databaseHandle = DBI->connect( "DBI:ODBC:Database\KTC.mdb", "", "", { RaideError => 1 } );
#$databaseHandle = DBI->connect( 'dbi:ODBC:DSN','','');
$databaseHandle = 'driver=Microsoft Access Driver (*.mdb);dbq=C:\Program Files\Apache Group\Apache2\Database\KTC.mdb'; $dbh = DBI->connect("dbi:ODBC:$DSN", '','') or die "$DBI::errstr\n";

# use ProductID to find a product name
# @TODO copied this query from another source -- change it for this screen
$productID=1; # placeholder until this screen is hooked to master list of products
$query1 = "SELECT ProductID, ProductName, ProductDescription, UnitsInStock, UnitPrice
           FROM Products WHERE ProductID = 1";

# @TODO add statement handle definition here (prepare query)
$statementHandle = $databaseHandle->prepare( $query1 );
# @TODO add statement handle execute here
$statementHandle->execute();

while ( @product = $statementHandle->fetchrow_array() )
{
# @TODO fill in fields below to correspond with SQL statement (anywhere "###" is)
      $price = sprintf ("\$ %.2f", ProductPrice); #format price
      print( "<tr>", td( "Product ID: " ), td( hidden("product_id",$productID).$productID ), "</tr>\n" );
      print( "<tr>", td( "Name: " ), td( ProductName ), "</tr>\n" );
      print( "<tr>", td( "Description: " ), td( ProductDescription ), "</tr>\n" );
      print( "<tr>", td( "Price: " ), td( hidden("unit_price",ProductPrice).$price ), "</tr>\n" );
      #print( "<tr>", td( "Quantity Available: " ), td( hidden("quantity_available", UnitsInStock), "</tr>\n" );
}

print( "</table>\n" );
print( "<table>" );
print( "<tr>", td( "Order Quantity: "),
               td( textfield( -name     => "quantity",
                            -value    => "",
                              -onChange => "validateQuantity(this)") ), "</tr>\n" );
print( "<tr>", td( "Requested Delivery Date: "),
               td( textfield( -name     => "delivery_date",
                            -value    => "",
                            -onChange => "validateDelivery(this)") ), "</tr>\n" );
print( "</table>\n" );
print( submit( -name  => "Order" ) );
print( "<p class=\"special\">\n",
      "   Customer: <i>Joe Smith, EduSoft, Inc.</i>\n",
      hidden("customer_id",8),
      "</p>\n" );
print( end_form );
print( end_html() );

# @TODO disconnect database, finish statement
$databaseHandle->disconnect();
$statementHandle->finish();

sub getClientValidationScripts {
$JSCRIPT=<<END;
        var validDate=false;
       var validNum=false;
      
       function validateForm() {
          if (validDate && validNum) {
             alert("Order accepted, please wait for confirmation screen.");
          } else {
             alert("Please enter a valid order quantity and requested date.");
          }
       }
      
         function validateQuantity(num){
            if (isInteger(num)){
                var numAvail =
                    parseInt(inventoryDetailOrder.quantity_available.value);
                if (num.value>0 && num.value<=numAvail) {
               validNum=true;
                } else {
                   alert(\"Please enter a quantity between 1 and \"+ numAvail +\".\");
               inventoryDetailOrder.quantity.value="";
                }
            } else {
                alert(\"Please enter a valid quantity.\");
            }
        }
       
      // check for valid date
      function validateDelivery(date) {
            if( isDate(date.value) ) {
             validDate=true;
            } else {
               inventoryDetailOrder.delivery_date.value="";
          }
         }
END
return $JSCRIPT;
}
ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMongerFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers