
June 24th, 2000, 02:47 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 10
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Hello,
I wrote a few days ago asking for help with inserting data into mysql with perl. Thanks to all who offered their help. I really am trying to learn perl, but I'm not a natural by any stretch. I am able to get the information in the database, but I know their is a much simpler way with loops. I've learned so much in the last two weeks, but not enough to slim this down. Here's the script that works, but is very lengthy:
#!/usr/bin/perl
use CGI;
use DBI;
$q=new CGI;
#get the parameter from the html form.
$name=$q->param('name');
$address=$q->param('addr');
$city=$q->param('city');
$state=$q->param('state');
$zip=$q->param('zip');
.
# goes on for years
print $q->header;
$dbh=DBI->connect('dbi:mysql:dbasename','user','passwd');
$sql="INSERT INTO main(name,address,city,state,zip...) values('$name','$address','$city','$state','$zip'...)";
# I know about the quote thingy, but how do I simplify the stuff before values?
$sth = $dbh->prepare($sql)
or die "Can't prepare $sql: $dbh->errstrn";
$rv = $sth->execute
or die "can't execute the query: $sth->errstrn";
if ($rv==1){
print "Record has been successfully updated !!!n";
}else{
print "Error!!while inserting recordn";
$dbh->disconnectO;
exit;
}
This is trimmed way down from the 21 variables in the script. I've been reading and studying other scripts. I just can't do it. My mind is fried from trying to figure this simple thing out. I will keep on studying. Any pointers appreciated. To lessen the length of this post, my email is ragamble@fortlewis.edu. Thanks.
Bob
|