grax has asked for the wisdom of the Perl Monks concerning the following question:

#!usr/perl/bin use CGI; use DBI; $cgi_object = new CGI; $n = 0; $error_message = "No Records Found...Please Select Again"; # $search_type_local = $cgi_object->param(search_type); # $employee_first_name_local = $cgi_object->param(employee_first_name) +; # $department_type_local = $cgi_object->param(department_id); $search_type_local = 0; $employee_first_name_local = "Graham"; $department_type_local = 1; sub create_query_type_0; sub create_query_type_1; sub execute_query_type_0; sub execute_query_type_1; $dbh = DBI->connect("DBI:ODBC:detailsstore", "anonymous", "password") +or die "Couldn't connect to database"; if ($search_type_local == 0){ &create_query_type_0; &execute_query_type_0; if ($sth->rows == 0){ print $error_message; } else { while ($sth->rows ne 0 & $n < 25){ @data = $sth->fetchrow_array(); # line 39 $formmated = $data[0] & " " & $data[1] & " " & $data[2] +& " " & $data[3]; # line 41 print $cgi_object->textfield('detailsresults', $formmate +d, 30, 50); $n = $n + 1; } } } else { &create_query_type_1; &execute_query_type_1; if ($sth->rows == 0){ print $error_message; } else { while ($sth->rows ne 0 & $n < 25){ @data = $sth->fetchrow_array(); $formmated = $data[0] & " " & $data[1] & " " & $data[2]; print $cgi_object->textfield('detailsresults', $formmate +d, 30, 50); $n = $n + 1; } } } $sth->finish; $dbh->disconnect; sub create_query_type_0{ $sth = $dbh->prepare("SELECT employee_table.employee_first_name, em +ployee_table.employee_last_name, employee_table.employee_extension, e +mployee_table.department_id FROM employee_table WHERE (((employee_table.department_id)=?));") +; } sub create_query_type_1{ $sth = $dbh->prepare("SELECT employee_table.employee_first_name, em +ployee_table.employee_last_name, employee_table.employee_extension FROM employee_table WHERE (((employee_table.employee_first_name)= +?));"); } sub execute_query_type_0{ $sth->execute($employee_first_name_local) or die "Couldn't execute +statement"; } sub execute_query_type_1{ $sth->execute($department_type_local) or die "Couldn't execute stat +ement"; }
Sorry about this but I am having a bit of a hard time at the moment with the syntax of some of the code.
I have another problem, with the following errors:
DBD::ODBC::st fetchrow_array failed: (DBD: no select statement currently executing err=-1) at line 39.
Could ^ this be to do with the scope of the prepare and execute statments?
Use of uninitialized value in bitwise and (&) at line 41.
Please could you help, this is for my final year project at college and I would appreciate any help you can give me.

Replies are listed 'Best First'.
Re: ODBC errors
by busunsl (Vicar) on May 16, 2001 at 17:07 UTC
    I think two things will help you here:

    The -w flag:  #!usr/bin/perl -w

    and strict:  use strict;

    With that you have to declare all global variable with my:

    my $dbh; my $sth;

    btw: what is #!usr/perl/bin ?

Re: ODBC errors
by c-era (Curate) on May 16, 2001 at 17:21 UTC
    As this is homework I probably shouldn't be helping you, but I'll give you a few hints.

    Line 41: It looks like you are confusing perl with VB. Take a look at string opertors.

    Line 39: Look at line 38, do you really need it? What would happen if you combine lines 38 and 39.

    Your subs: Are they neccissary? If you 'use strict' you will get many errors with your current subs, is there a way to pass the object?

    I hope that this gives you some direction.

      There's such a fine line between *helping* a person with their homework and *doing* their homework. I don't think there's any problem with asking a question on Perl monks, even if it is homework. Now if he/she said they wanted the perlmonks to write the entire thing, then ok, I see the problem, but helping out is exactly what the Perl community is about. I have seen some people really stumble over that line though. <G>

      Thanks for the reply also because being a VB and a Perl coder by profession, I also missed the ampersands(&) and didn't see that as the problem.