Hello everybody
What im trying to do just to start is have a page that i can add entries to a mysql database from a perl script-
add.pl is the script i use for this
#!/usr/bin/perl -w
use CGI;
use DBI;
print CGI::header();
my $username = dbquote(CGI:
aram('name'));
my $email = dbquote(CGI:
aram('email'));
unless ($username) {
print <<PAGE;
<h1>Add a Subscriber</h1>
<form action=add.pl method=post>
Name: <input type=text name=name><br>
Email: <input type=text name=email><br>
<input type=submit value="Add Subscriber">
</form>
PAGE
exit;
}
###### CONNECT TO DATABASE #################
my $dbh = DBI->connect("dbi:mysql:shoes:localhost:3306", "user", "pass");
####### PREPARE QUERY #######################
my $sth = $dbh->prepare("insert into subscribers(username, emailaddr)
values('$username', '$email')");
######## EXECUTE QUERY #####################
$sth->execute();
print <<PAGE;
<h1>User Added</h1>
The user $username was just added. Want to <a href=add.pl>add
another</a>?
PAGE
sub dbquote {
my($str) = @_;
$str =~ s/"/\\"/g;
$str =~ s/\\/\\\\/g;
$str =~ s/'/\\'/g;
}
my view.pl file seems to work fine
#!/usr/bin/perl -w
use DBI;
use CGI;
print CGI::header();
print "<h1>Subscribers</h1>";
#connect
my $dbh = DBI->connect("dbi:mysql:shoes:localhost:3306", "root", "sundin_13");
#prepare query
my $sth = $dbh->prepare("select username, emailaddr from subscibers");
#execute query
$sth->eecute();
while(my ($username, $email) = $sth->fetchrow_array()) {
print "$username: $email<br>\n";
}
My problem is when i type in values in the boxes and click add subscriber the script seems to run no errors but no entry in the database get added. I should see the resultswith view.pl and as well manually going in to mysql but i dont
im am stuck at this point any help is greatly appreciate
Thank you
Robert