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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to CGI - Please help

Status
Not open for further replies.

SkyHigh

Technical User
May 30, 2002
309
CA
Hi Folks

I need to create a simple web application that connects to a PostgreSQL database, to insert, update, delete records from one single table.

I have never done that before using CGI or any other web tools.

I know how to make application connect to the database.

Any advise, sugguestions or links to useful sites would be much appreciated.

Thanks
Brenda
 
Brenda,
Look over at the Perl forum, look at the FAQ's, and if you have specific questions please do a quick search of the forums first

Best of Luck
Regards
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
What OS and web server?

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Hi

I am using RedHat and Appache as the webserver

Rgds
Brenda
 
I'd suggest a divide and conquer approach. Figure out a little CGI and then figure out a little Perl/DBI.

There are a couple of faqs on CGI under the 'FAQS' tab at the top of this page. CGI (faq452-653) and Common Problems (faq452-1816).

Once you know how to spell CGI, take a look at the DBI faqs in the perl forum. Also, there is a very good book, "Programming the Perl DBI" by Descarte and Bunce published by O'Reilly. If you're new to Perl/DBI, this is $35 well spent.

Once you can spell CGI and DBI, putting the two together is reasonably easy.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Here is a very simple example of a CGI app that connects to a SQL Server instance.

Code:
#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
use CGI::Carp 'warningsToBrowser';
use DBI;

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

my $dbh = DBI->connect("dbi:Sybase:server=serverName", 'userName', 'db_password', {PrintError => 1, RaiseError => 1});
unless ($dbh) { die "Unable for connect to server $DBI::errstr"; }
$dbh->do('use pubs');

my $sql = "select * from authors";
my @data;
my $sth = $dbh->prepare("$sql");
if($sth->execute)
	{ while(my @row = $sth->fetchrow) { print &quot;@row<br />\n&quot;; }}
else { print &quot;ERROR - $DBI::errstr\n&quot;; }
$sth->finish;

print 	qq(<p>End Here</p>),
	$cgi->end_html;

There are an infinite number of variations on this theme.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top