in reply to DBI connection through CGI

Hi Phemur,

Try changing this line:

$dbHandle = DBI->connect('DBI:mysql:mydb','ID','pw');

to this:

my $dbh = DBI->connect("DBI:mysql:database=dbname;host=host", "$id","$ +pw") || die "Can't connect: $DBI::errstr";

If you start your CGI form like this:

#!/usr/bin/perl -wT use strict; use CGI qw( :standard ); use CGI::Carp qw( fatalsToBrowser ); use DBI; use DBD::mysql; #Store each field in a variable. my $name = param("name"); my $phone = etc.. my $age = etc.. my $sth; #Then insert each of them into a table: $sth = $dbh->prepare("INSERT INTO userdata VALUES (?,?,?)"); $sth->execute($name, $phone, $age); #Make sure you clean up when finished: $sth->finish(); $dbh->disconnect();
Warning: This code is untested but it should help you complete the project.

Hope this helps,
-Katie.

Replies are listed 'Best First'.
Re: Re: DBI connection through CGI
by Phemur (Beadle) on May 20, 2002 at 21:30 UTC
    Hi Katie,

    Thanks for the information and code sample. I tried your suggestions, and although it didn't help that particular problem, it did polish my code and teach me a few things. I've only been trying my hand at Perl for a week or so now, and this does help.

    Do you have any tips on making a C programmer's Perl scripts look less like C and more like Perl? :-)

    Thanks a bunch.

    Nat (Phemur)