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

Im new to perl, have create a few scripts which work fine on command lin eon my linux box, i need to create a simple insert, search and delete user frontend i.e. a cgi script which can be accessed via the web.
I keep getting the below error

Can't locate object method "Execute" via package "DBI::db" at /usr/local/apache2/cgi-bin/project2.cgi line 18.

Heres the code...........
#!/usr/bin/perl use CGI; use CGI::Carp qw(fatalsToBrowser); use vars qw($Query $dbh $sth $Value); $Query = new CGI( ); use DBI; $dbh = DBI->connect("DBI:mysql:exelstock") or die "Cannot connect: " . $DBI::errstr; $Value = $Query->param('Value'); $sth = $dbh->prepare("SELECT * FROM walstock WHERE name='$Value'"); $dbh->execute($sth); print "Content-type: text/html\n\n"; print "<HTML>\n"; print "<BODY>\n"; while (@results = $sth->fetchrow_array) { print "@row\n"; } $sth = $dbh->finish(); $dbh->disconnect(); print "</BODY>\n"; print "</HTML>\n";

20050316 Edit by ysth: code tags

20050318 Edit by Corion: Changed title from 'Help im new so so late for uni project!!'

Replies are listed 'Best First'.
Re: Help with uni project: DBI errors in CGI script
by dragonchild (Archbishop) on Mar 16, 2005 at 14:07 UTC
    You call execute() on the $sth, not the $dbh. Same with finish(). You call prepare() and disconnect() on the $dbh, as you correctly are doing.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: Help with uni project: DBI errors in CGI script
by RazorbladeBidet (Friar) on Mar 16, 2005 at 14:09 UTC
    Execute is a command for the statement handler, not the db handler. If you want to operate on the db handler, the method is "do"
    --------------
    It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Help with uni project: DBI errors in CGI script
by jZed (Prior) on Mar 16, 2005 at 20:29 UTC
    Is there anything in param('Value')? If not, nothing would get displayed. Could there something dangerous in param('Value')? If so, use placeholders. And finally, assuming that 'Value' has a value, is there a row where the specified field exactly matches that value (including spaces, case, etc.) in the database?
      There is a field called name and i have three records with names of stock items. I have tried all of them.
      Heres the html form im using

      <HTML>
      <HEAD><TITLE> Stock Search System </TITLE></HEAD> <BODY>
      <FORM METHOD="POST" ACTION="/cgi-bin/project2.cgi">
      Enter Stock name: <INPUT TYPE=TEXT NAME=Value>
      <INPUT TYPE="SUBMIT">
      </FORM>
      </BODY>
      </HTML>
        Well, first do what everyone has told you: change @results = $sth->fetchrow_array to @row = $sth->fetchrow_array. What I was suggesting by asking you if there was a param('Value') was that you should check in your script if something was entered in the field before attempting to query the database using the field. Yes, you have a field with that name in your form, but your script so far has no way to tell if the user put anything in that fields before clicking "submit".