1 #!/usr/bin/perl
Lines 2 - 24 are just comments.
25 my $Me;
26 ($Me =$0) =~ s|^.*/||;
27
28 #use lib '.';
29 use tc;
30 use CGI;
31 use CGI::Carp qw(fatalsToBrowser);
32 use strict;
33 #use warnings;
34
35
36 my $p = ''; # page contents
37 my $r = undef; # redirect-to url
38
39 my $op = $cgi->param('op');
40 my $cust_id = $cgi->param('cust_id');
41 my $submit = $cgi->param('submit');
42 my $fname = $cgi->param('fname');
43 my $lname = $cgi->param('lname');
44 my $address1 = $cgi->param('address1');
45 my $address2 = $cgi->param('address2');
46 my $city = $cgi->param('city');
47 my $state = $cgi->param('state');
48 my $zip = $cgi->param('zip');
49 my $phone = $cgi->param('phone');
50 my $alt_phone = $cgi->param('alt_phone');
51 my $user = $cgi->cookie('user');
52 $user or $user = $cgi->param('user');
53
54
55 $op or $op = 'NUL';
56
57 OP: {
58 &add_cust(), last OP if $op =~ /^add_cust
$/;
59 &suspense(), last OP if $op =~ /^suspense
$/;
60 &add_pol(), last OP if $op =~ /^add_pol$/;
61 &head();
62 }
63 $dbh->disconnect();
Lines 64-89 is code that I'm not using yet.
90 sub add_cust(){
91 &head(); #this just points to sub head() where an image is
located.
92 #print "Content-type: text/html";
93 if ($submit){
94 #print "Content-type: text/html";
95 print STDERR;
96 my $sql = "insert into customers set " .
97 "fname=" . $dbh->quote($fname) .
98 ",lname=" . $dbh->quote($lname) .
99 ",address1=" . $dbh->quote($address1) .
100 ",address2=" . $dbh->quote($address2) .
101 ",city=" . $dbh->quote($city) .
102 ",state=" . $dbh->quote($state) .
103 ",zip=" . $dbh->quote($zip) .
104 ",phone=" . $dbh->quote($phone) .
105 ",alt_phone=" . $dbh->($alt_phone);
106 my $rv = $dbh->do($sql) or die "do failed: $!\n";
107 }else{
108 #print "Content-type: text/html\n\n";
109 #&head();
110 print $cgi->start_table({-align=>"center", -
border=>"1", -width=>"80%"});
111 print "<TR><TD>\n";
112 print "Add Customer.\n";
113 print "</td></tr>\n";
114 print $cgi->start_form();
115 print $cgi->hidden('op', 'add_cust');
116 print "<tr><td>" .
117 "First Name:" . $cgi->textfield('fname','',
50,75) .
118 "Last Name:" . $cgi->textfield('lname','',
50,75) .
119 "Address 1:" . $cgi->textfield('address1','',
50,75) .
120 "Address 2:" . $cgi->textfield('address2','',
50,75) .
121 "City:" . $cgi->textfield('city','',50,75) .
122 "State:" . $cgi->textfield('state','',50,75) .
123 "Zip:" . $cgi->textfield('zip','',50,75) .
124 "Phone:" . $cgi->textfield('phone','',50,75) .
125 "Alt Phone:" . $cgi->textfield('alt_phone','',
50,75);
126 print $cgi->submit('submit','Add Customer/Prospect');
127 print "</td></tr>";
128 print $cgi->end_table();
129 }
130 }
The above code produces this error (below). I am still new to perl so
I'm sure there is something obvious that I'm missing. My system is Mac
OSX 10.3 with the installation of perl that it came with. I installed
DBD-mysql-4.001 and DBI-1.53.1.
Please don't flame me. If I could solve this on my own I would have. I
only post on Google groups as a last resort. I'd appreciate if anybody
would point me in the right direction. Thanks in advance.
Software error:
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 39.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 40.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 41.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 42.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 43.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 44.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 45.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 46.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 47.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 48.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 49.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 50.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 51.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 52.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 63.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 97.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 98.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 99.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 100.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 101.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 102.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 103.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 104.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 105.
Global symbol "$dbh" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 106.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 110.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 114.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 115.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 117.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 118.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 119.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 120.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 121.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 122.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 123.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 124.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 125.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 126.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 128.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 134.
Global symbol "$cgi" requires explicit package name at /Library/
WebServer/Documents/moultrie_intl/policies.cgi line 136.
Execution of /Library/WebServer/Documents/moultrie_intl/policies.cgi
aborted due to compilation errors.
For help, please send mail to the webmaster ([no address given]),
giving this error message and the time and date of the error.
When I comment out use strict; I get the following message:
Software error:
Not a CODE reference at /Library/WebServer/Documents/moultrie_intl/
policies.cgi line 96.
For help, please send mail to the webmaster ([no address given]),
giving this error message and the time and date of the error.
Tonya
Ok, I placed all of the tc.pm file in the policies.cgi just to rule
out any problem of reading that file and I still get the error "not a
CODE reference at line 101". Here's the new code.
1 #!/usr/bin/perl -w
25 my $Me;
26 ($Me =$0) =~ s|^.*/||;
27
28 #use lib '.';
29 use lib '/usr/lib/perl5.8.1';
30 #use tc;
31 use CGI;
32 use DBI;
33 use CGI::Carp qw(fatalsToBrowser);
34 #use strict;
35 #use warnings;
36
37 my $dbh = DBI->connect("DBI:mysql:databasename", "username",
"password");
38
39 my $cgi = new CGI;
40
41 my $p = ' '; # page contents
42 my $r = undef; # redirect-to url
43
95 sub add_cust(){
96 &head();
97 #print "Content-type: text/html";
98 if ($submit){
99 #print "Content-type: text/html";
100 print STDERR;
101 my $sql = "insert into customers set " .
102 "fname=" . $dbh->quote($fname) .
103 ",lname=" . $dbh->quote($lname) .
104 ",address1=" . $dbh->quote($address1) .
105 ",address2=" . $dbh->quote($address2) .
106 ",city=" . $dbh->quote($city) .
107 ",state=" . $dbh->quote($state) .
108 ",zip=" . $dbh->quote($zip) .
109 ",phone=" . $dbh->quote($phone) .
110 ",alt_phone=" . $dbh->($alt_phone);
111 my $rv = $dbh->do($sql) or die "do failed: $!\n";
112 }else{
113 #print "Content-type: text/html\n\n";
114 #&head();
115 print $cgi->start_table({-align=>"center", -
border=>"1", -width=>"80%"});
116 print "<TR><TD>\n";
117 print "Add Customer.\n";
118 print "</td></tr>\n";
119 print $cgi->start_form();
120 print $cgi->hidden('op', 'add_cust');
121 print "<tr><td>" .
122 "First Name:" . $cgi->textfield('fname','',
50,75) .
123 "Last Name:" . $cgi->textfield('lname','',
50,75) .
124 "Address 1:" . $cgi->textfield('address1','',
50,75) .
125 "Address 2:" . $cgi->textfield('address2','',
50,75) .
126 "City:" . $cgi->textfield('city','',50,75) .
127 "State:" . $cgi->textfield('state','',50,75) .
128 "Zip:" . $cgi->textfield('zip','',50,75) .
129 "Phone:" . $cgi->textfield('phone','',50,75) .
130 "Alt Phone:" . $cgi->textfield('alt_phone','',
50,75);
131 print $cgi->submit('submit','Add Customer/Prospect');
132 print "</td></tr>";
133 print $cgi->end_table();
134 }
135 }
I will keep working on it and if I find the solution before someone
replies I'll post it.
Tonya
Ok, problem solved. I don't understand why, but this is what I did. I
was desperate and didn't really think it would work but I went to a
similar script I had working before that would add a record to an
address book. I took the section that was similar and pasted it over
lines 101 to 110 and modified about 3 fields to match the database I
wanted to call from. It added the record successfully. I don't see
anything different. I put the old code that I posted here in the last
post and the new code in my terminal window and as far as I can tell
it matches word for word. I checked the database and confirmed the
record was there. Oh well, I hope this helps somebody else. Just
thought I'd post what I found. Now I can finally sleep. :)
Tonya