[GENERAL] Postgres' DBI(Pg) problems.

From: "R\imi Lehn" <Remi(dot)Lehn(at)irin(dot)univ-nantes(dot)fr>
To: Kevin Lo <jwlo(at)ms11(dot)hinet(dot)net>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: [GENERAL] Postgres' DBI(Pg) problems.
Date: 1999-01-18 09:10:48
Message-ID: 13986.62142.701726.19922@kir.performanse.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Your script worked for me (I skipped everything related to
forms-lib), but :

- /* xxxx */ C-style comments are not allowed by perl (line #2)
- you should $sth->finish() and $dbh->disconnect() at the end of your
script to avoid warnings ("Database handle destroyed without
explicit disconnect.")

I assumed that your table course has two fields, both are
type text. Check that your fields are not numbers (inserted values
are quoted (line #13)).

You can replace $sth->prepare() and $sth->execute() by a
$sth->do( "your query" ); as your query has no output row.

Check your web server's logs. At least for apache, stderr
of cgi scripts is dumped in an error log. Try running your script
offline. A common mistake is not having access to your database
with the uid endorsed by your web server (apache usually runs
cgi scripts as nobody which may not have INSERT permissions on
the table).

Hope it will help.
Rémi.

Kevin Lo writes:
> Hi,
>
> I'm trying to use Postgres DBI, which is Pg, to write a simple cgi script.
> But I encounter a problem, hope anyone can tell me how to do, thanks.
>
> For example:
> I have two input forms in ex.html, which names are 'id' and 'student'.
> I want to insert them into 'course' table in student database by using Pg.
> The script I wrote as following:
>
> #!/usr/local/bin/perl
> require 'forms-lib.pl';/* this script gets form values in HTML that I input */
> use DBI;
> print "Content-type: text/html\n\n";
> print "<HTML>\n";
> print "<HEAD>\n";
> print "<TITLE>Data inserted</TITLE>\n";
> print "</HEAD>\n";
> %input = &GetFormInput();
> $v1 = $input{'id'};
> $v2 = $input{'student'};
> $dbh = DBI->connect("dbi:Pg:dbname=student") or die $DBI::errstr;
> $sth = $dbh->prepare("insert into course values('$v1', '$v2')")
> or die $DBI::errstr;
> $sth->execute or die $DBI::errstr;
> print "<BODY>\n";
> print "<H1>Data inserted!</H1>\n";
> print "</BODY>\n";
> print "</HTML>\n";
>
> After executing this script, I just see brower's title "Data inserted",
> I can't see "Data inserted!" in HTML and can't insert values into 'course'
> table. I don't know how to do, would anyone tell me, thanks in advance.
>
> Best regards,
> Kevin.
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gilles Darold 1999-01-18 11:43:44 Re: [GENERAL] How to display stored image on web page?
Previous Message Dave Van Abel 1999-01-16 15:57:19 Postgres Archive for Sample Code