Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert into database

Status
Not open for further replies.

cnw40007

Technical User
Mar 4, 2003
35
IE
Hi I'm trying to enter values into a mysql databse from my webserver.My problem is that from the web server i can enter a value into the database, it tells you the value has been entered but when i check the databse it is not there. This is my code

#!/usr/bin/perl

use CGI qw:)standard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;


my $username = 'root';
#my $password = '';

my $dbh = DBI->connect("DBI:mysql:spamdb",$username) || die "Error connecting: '$DBI::errstr'";

my $address = param('email');
my $subject = param('subject');

my $sql = "INSERT INTO addsubj (address,subject) VALUES ($address,$subject)";

my $sth = $dbh->prepare($sql) || die "Error preparing: DBI:errstr";

$sth->execute;

print header;

print qq(<h1> Values Entered</h1>);
print qq(<br> Email address : $address <br>);
print qq(<br> Email subject : $subject<br>);

end_html();
$dbh->disconnect;
Does anybody know where i am going wrong?? Thank you..
 
Im not sure what you mean, can you explain?Thanks
 
When storing information to a database, unless the AutoCommit function is on, you have to explicitly commit the transaction.

To be honest, I haven't used DBI module, but the premise is the same. Check the documentation for MySQL to see if there's an autocommit function.

What basically happens is that the transaction is stored in your userspace, but isn't actually committed to the database until you tell it to. The userspace involved would be that of the webserver, and not the interactive one you would have.

As I say haven't used it ... so I could be sending you up the wrong tree, but if your script is getting as far as your print statements without errors, then its the only thing I can think of

HTH

;Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top