Forum Moderators: coopster & phranque

Message Too Old, No Replies

ERROR: Can't locate object method "new" via package "CGI"

         

harrinju

10:14 pm on Mar 10, 2007 (gmt 0)

10+ Year Member



I am running a perl program that inputs data from a web page(reg.html) into a mysql database and then it'ssupposed to redirect to another web page. It works until I get to the redirect code at the end of the program ($q = new CGI;). It tells me that it cant read the "new" object in the CGI package. I am new at this stuff so I dont really know if i'm using the right package or not(or even where to look for the right package). i've tried "use CGI;" but that didnt work. I'm running Apache Server(dont know which version). This is my program: reg.pl
#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";

#header for the ouput html file

#these are the default paths to search for files
push(@INC,"/var/apache/cgi-bin/");

#this subroutine extracts the data sent from the html program
#forms-lib.pl is found at /var/apache/cgi-bin/
require("forms-lib.pl");

#subroutine loads data into input hash array
%input = &GetFormInput();

#bring data into perl program

$firstname = $input{fname};
$lastname = $input{lname};
$uname = $input{uname};
$password = $input{pass};
$address = $input{address};
$city = $input{city};
$state = $input{state};
$zip = $input{zip};

use DBD::mysql;
use DBI;

$dbh=DBI->connect("dbi:mysql:me:131.xx.xx.xx:3306","me",'pass');
$sth = $dbh->prepare("INSERT INTO customer VALUES ('$firstname','$lastname','$uname','$password','$address','$city','$state','$zip')");
$sth->execute();

$sth->finish();

$dbh->disconnect();

$q = new CGI; #THIS IS THE PROBLEM!
print $q->redirect(" [myURL:port#...] ");
exit;
-------------------------------------------------------------------
this is the html: reg.html
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2900.3059" name=GENERATOR></HEAD>
<BODY>
<H1>
<CENTER>KBAY </CENTER></H1>
<P><FORM method=Post action=/cgi/kbay/reg.pl>
<P>Please fill out the following information for registration below.
<P>
<P>First Name: <INPUT type="text" name="fname"> Last Name: <INPUT type="text" name="lname">
<P>User name: <INPUT type="text" name="uname"> (your email address can be your username)

<P>password: <INPUT type="password" name="pass">
<P>
<P>Address: <INPUT type="text" name="address"> &nbsp;&nbsp; City: <INPUT type="text" name="city"> State:<INPUT type="text" name="state">
<P>Zip Code: <INPUT type="text" name="zip">
<P>
<INPUT name="SUBMIT" type="SUBMIT" value="reg">
</FORM>
</BODY></HTML>

this is what my log file says:[Sat Mar 10 16:42:29 2007] [error] [Sat Mar 10 16:42:29 2007] reg.pl: Can't locate object method "new" via package "CGI" (perhaps you forgot to load "CGI"?) at /var/projects/cps3500/groucho/cgi-bin/kbay/reg.pl line 42., referer: [myURL...]
please help.

[edited by: jatar_k at 4:49 am (utc) on Mar. 11, 2007]
[edit reason] removed specifics [/edit]

perl_diver

7:58 am on Mar 11, 2007 (gmt 0)

10+ Year Member



You never loaded the CGI module. The CGI::Carp module is not the CGI module. You need to add:

use CGI;

but if all you need it for is the redirect I would just hard code the redirect stuff. Plus the redirect will not work as you have already printed an http header at the beginning of the script.

harrinju

5:24 pm on Mar 11, 2007 (gmt 0)

10+ Year Member



I used "use CGI;" already and I forgot to mention that when i click on the form button(which is how i want it to work) it gives me a status: 302 location moved url(or somthin like that) on the page

also I put this <meta blabla-equiv="Rfresh" bla bla url=bla/bla/index.html> in my html and it puts up a link to go to that page instead of automatically redirecting to that page.

lastly, how am i supposed to see the script if i dont have the html header at the top.

harrinju

5:25 pm on Mar 11, 2007 (gmt 0)

10+ Year Member



at the bottom of my last message i wanted to say how was it(html) supposed to see the script if i dont have the header in there

perl_diver

6:48 pm on Mar 11, 2007 (gmt 0)

10+ Year Member



there is no html in the perl script. Remove this line:

print "Content-type: text/html\n\n";

and the redirect should work OK.

harrinju

10:22 pm on Mar 11, 2007 (gmt 0)

10+ Year Member



I got it. thanks man. Actually it was the header and my permissions were wrong on my html file. i'm in a group my teammate made the html file that i was trying to redirect to. He set his permissions to: -rwxr-xr-x. Since i didnt have ownership to his file i just created a new file and cut and pasted his stuff to mine. I just left my new html file to u+rw, and it works.