catonthecouchproductions
asked on
Two actions - Two submit buttons
I have this page - http://elan.champlain.edu/~rcoughlin32001/booksonline.html - and submits the data to a database.
The first button submits the page to the database
The second button i want to be able to retrieve the password based on the account number given.
I am confused on how to make each a different action. I have them as two different names..but am not sure how to call them in Perl. In PHP I know you can do a REQUEST say and have it equal a name.
I am thinking a simple IF ELSE
IF CREATE
CREATE ACCOUNT
ELSE RETRIEVE
RETRIEVE PASSWORD
SQL SELECT STATEMENT FROM DB
Any ideas?
Thanks,
Ryan
The first button submits the page to the database
The second button i want to be able to retrieve the password based on the account number given.
I am confused on how to make each a different action. I have them as two different names..but am not sure how to call them in Perl. In PHP I know you can do a REQUEST say and have it equal a name.
I am thinking a simple IF ELSE
IF CREATE
CREATE ACCOUNT
ELSE RETRIEVE
RETRIEVE PASSWORD
SQL SELECT STATEMENT FROM DB
Any ideas?
Thanks,
Ryan
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser); # errors will fall to browser and be printed
use DBI;
use strict;
print "Content-type:text/html \n\n";
# username and password for the user
my $acc_num = param('acc_num');
my $password = param('password');
# login information
my $database = "rcoughlin32001";
my $dbuser = "rcoughlin32001";
my $dbpass = "lacrosse";
# select, type, database, server
my $dsn = "DBI:mysql:$database:localhost";
# connect
my $dbh = DBI -> connect($dsn, $dbuser, $dbpass, {RaiseError => 1}) or die "Error connecting: $DBI::errstr\n";
# encrypt then store in database
# replace a-k with 0-9
$password =~ tr/[a-k]/[0-9]/;
# store data in database
my $query = $dbh -> prepare("INSERT INTO bookaccounts (ID, acc_num, password) VALUES (null, '$acc_num', '$password')");
my $done = $query -> execute();
if($done){
print "Added to database.<br />";
}else{
print "Didn't add to database. <a href=\"../booksonline.html\">Click</a> to go back.<br /><br />";
}
# for debug
print "<b>OUTPUT</b><br /><br />";
print "<b>Account Number:</b> " . $acc_num . "<br/>";
print "<b>Password:</b> " . $password;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both!
Ryan
Ryan
ASKER
Worked like a charm!
Thanks again,
Ryan
Thanks again,
Ryan
ASKER
I get this:
>>Can't call method "execute" on an undefined value at booksonline.cgi line 54.
Line 54: my $sth-> execute;
Any ideas? And to decrypt..does that look right..what i have in my code?
Thanks!
Open in new window