soyunlocofl
04-21-2005, 03:18 PM
Hi can someone please help me to display everything that is in my table named Customer. I can figure out how to do it. Thanks in advance.
Here the complete code:
#!/usr/bin/perl
use CGI qw(:standard);
use DBI;
use webdb3;
## Connecting to the database
$dbh = webdb3::connect_mdcLinux;
##declare globla stuff
print "Content-type:text/html\n\n";
print "<html><head><title>SUBSCRIPTION</title></head>\n";
&getstuff;
&updatedb;
&buildquery;
&getallrecords;
exit;
sub getstuff{
#get variables
$name = param('name');
$name = ucfirst($name);
$address = param('address');
$address1 = param('address1');
$state = param('state');
$CustomerNumber= int (rand(2500));
$city = param('city');
$city = ucfirst($city);
$zip_code = param('zip_code');
$phone = param('phone');
$email = param('email');
$card_type = param('card_type');
$card_number = param('card_number');
$card_number =~ s/\d{4}$/****/;
$month = param('month');
$year = param('year');
$ip = $ENV{'REMOTE_ADDR'};
}
sub updatedb{
$query = "INSERT INTO Customer(
CustomerNumber, Name, Email, Address, Address1, City, State, Zip, Phone, DateCreated)
VALUES (
'$CustomerNumber', '$name', '$email', '$address', '$address1', '$city', '$state', '$zip_code', '$phone', NOW());";
$sth = $dbh->prepare($query);
$sth->execute() or webdb3::dberr_trap("Unable to insert into ATABLEINYOURDATABASE table of STAFF db");
$sth->finish();
}
sub buildquery {
$query = qq(SELECT * FROM Customer);
$sth = $dbh->prepare($query);
$sth->execute() or webdb3::dberr_trap("Unable to query TIMELOG table of STAFF db");
# assign fields to variables
$sth->bind_columns(\$CustomerID, \$CustomerNumber, \$Name, \$Email, \$Address, \$Adrees1, \$City, \$State, \$Zip,
\$Phone, \$DateCreated);
}
sub getallrecords {
# output computer list to the browser this while loop gets all of the records
# that satisfy the query and for each record it creates a row in an html table
while($sth->fetch()) {
print Tr(
td($CustomerID), td($CustomerNumber), td($Name), td($Email), td($Address), td($Address1),
td($City), td($State), td($Zip), td($Phone), td($DateCreated)
);
$dbh->disconnect;
}
Here is my form:
http://147.70.30.32/noetse/noetse.html
Here the complete code:
#!/usr/bin/perl
use CGI qw(:standard);
use DBI;
use webdb3;
## Connecting to the database
$dbh = webdb3::connect_mdcLinux;
##declare globla stuff
print "Content-type:text/html\n\n";
print "<html><head><title>SUBSCRIPTION</title></head>\n";
&getstuff;
&updatedb;
&buildquery;
&getallrecords;
exit;
sub getstuff{
#get variables
$name = param('name');
$name = ucfirst($name);
$address = param('address');
$address1 = param('address1');
$state = param('state');
$CustomerNumber= int (rand(2500));
$city = param('city');
$city = ucfirst($city);
$zip_code = param('zip_code');
$phone = param('phone');
$email = param('email');
$card_type = param('card_type');
$card_number = param('card_number');
$card_number =~ s/\d{4}$/****/;
$month = param('month');
$year = param('year');
$ip = $ENV{'REMOTE_ADDR'};
}
sub updatedb{
$query = "INSERT INTO Customer(
CustomerNumber, Name, Email, Address, Address1, City, State, Zip, Phone, DateCreated)
VALUES (
'$CustomerNumber', '$name', '$email', '$address', '$address1', '$city', '$state', '$zip_code', '$phone', NOW());";
$sth = $dbh->prepare($query);
$sth->execute() or webdb3::dberr_trap("Unable to insert into ATABLEINYOURDATABASE table of STAFF db");
$sth->finish();
}
sub buildquery {
$query = qq(SELECT * FROM Customer);
$sth = $dbh->prepare($query);
$sth->execute() or webdb3::dberr_trap("Unable to query TIMELOG table of STAFF db");
# assign fields to variables
$sth->bind_columns(\$CustomerID, \$CustomerNumber, \$Name, \$Email, \$Address, \$Adrees1, \$City, \$State, \$Zip,
\$Phone, \$DateCreated);
}
sub getallrecords {
# output computer list to the browser this while loop gets all of the records
# that satisfy the query and for each record it creates a row in an html table
while($sth->fetch()) {
print Tr(
td($CustomerID), td($CustomerNumber), td($Name), td($Email), td($Address), td($Address1),
td($City), td($State), td($Zip), td($Phone), td($DateCreated)
);
$dbh->disconnect;
}
Here is my form:
http://147.70.30.32/noetse/noetse.html