CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Won't write to database

 



spike4000
Novice

Feb 17, 2005, 12:42 PM

Post #1 of 2 (436 views)
Won't write to database Can't Post

When I press "save", it doesn't save to the database (Oracle)? What's wrong below?
============================
my $p1 = param('col1');
my $dbh1 = DBI->connect("DBI:Oracle:$sid", "$dbuser", "$pw",{AutoCommit=>1});
($p2, $p3, $p4) = $dbh1->selectrow_array("SELECT col2, col3, col4 FROM table WHERE col1 = '$p1'");
print "Edit";
print "<form method=\"post\" action=\"e2.pl\">";
print "P3:<input type=text value=\"$p3\" name=p3>";
print "P4:<input type=text value=\"$p4\" name=p4>";
print "<input type=submit name=edit value='SAVE CHANGES'>";
print "</form>";
my $dbh = DBI->connect("DBI:Oracle:$sid", "$dbuser", "$dbpw",{AutoCommit=>1});
my $sth = $dbh->prepare("UPDATE table SET col3='$p3', col4='$p4' WHERE col1 = '$p1'");
$sth->execute;
=============================


davorg
Thaumaturge / Moderator

Feb 18, 2005, 2:31 AM

Post #2 of 2 (428 views)
Re: [spike4000] Won't write to database [In reply to] Can't Post


In Reply To
When I press "save", it doesn't save to the database (Oracle)? What's wrong below?

Code
my $p1    = param('col1'); 
my $dbh1 = DBI->connect("DBI:Oracle:$sid", "$dbuser", "$pw",{AutoCommit=>1});
($p2, $p3, $p4) = $dbh1->selectrow_array("SELECT col2, col3, col4 FROM table WHERE col1 = '$p1'");
print "Edit";
print "<form method=\"post\" action=\"e2.pl\">";
print "P3:<input type=text value=\"$p3\" name=p3>";
print "P4:<input type=text value=\"$p4\" name=p4>";
print "<input type=submit name=edit value='SAVE CHANGES'>";
print "</form>";
my $dbh = DBI->connect("DBI:Oracle:$sid", "$dbuser", "$dbpw",{AutoCommit=>1});
my $sth = $dbh->prepare("UPDATE table SET col3='$p3', col4='$p4' WHERE col1 = '$p1'");
$sth->execute;


In my experience, with Oracle the hardest part is getting everything set up correctly so you can connect to the database :)

You don't check that either of your connections are successful. Maybe you're not connecting to the DB at all.

Are you getting any errors in the web server error log?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives