By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

Perl script to put user input to MySQL database

P: 1
Hello i need some help with a script i am working on i have a mailserver and all users accounts are stored in a MySQL database.

I need to have a perl script that will take the user input and run the following database commands.

INSERT INTO domains (domain) VALUES ('');
INSERT INTO users (email, password) VALUES ('', ENCRYPT('password'));

this is what i have so far

#!/usr/bin/perl -w
use strict;
use warnings FATAL => 'all';
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use DBD::mysql;

my $cgi = CGI->new;
print $cgi->header, $cgi->start_html;

my $domains = $cgi->param('domains');
my $email = $cgi->param('email');
my $pasword = $cgi->param('password');
my $database = "mail";
my $host = "localhost";
my $user = "user";
my $pw = "password";
my $dsn = "dbi:mysql:$database:localhost:3306";
my $dbh = DBI->connect($dsn, $user, $pw,
{ RaiseError => 1 })
or die "unable to connect:$DBI::errstr\n";

my $query = "INSERT INTO domain (domain) VALUES (?,?)";
my $sth = $dbh->prepare($query);

$sth->execute($domains, $email);

# additional processing as needed ...

print $cgi->end_html;

any help is greatly apretiated
May 24 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.