1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Rep Power

    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:


    use CGI;
    use DBI;
    $q=new CGI;
    #get the parameter from the html form.

    # goes on for years

    print $q->header;


    $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";
    print "Error!!while inserting recordn";


    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.

  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Rep Power

    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 -

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

IMN logo majestic logo threadwatch logo seochat tools logo