Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 24th, 2000, 02:47 AM
frogman frogman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 10 frogman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old June 24th, 2000, 06:13 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

but not enough to slim this down. Here's the script that works, but is very lengthy:


You can optimize a script in different ways.

Probably you can write a subroutine and pass your queries to it.That subroutine will process the query and give you the result.so you can use that subroutine through out the project for database manipulation.

First learn perl very well .then you will be getting a very good understanding about what you want to do...




------------------
SR -
shiju.dreamcenter.net

"The fear of the LORD is the beginning of knowledge..."

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > simplifying this script

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap