Professional Web Applications Themes

How to track the success of insert - PERL Beginners

Hi I was trying out some practice examples with DBI and CGI and kind of stuck while doing a comparison That is if I could insert successfully into a databse a script window shld come "Success". but when the insert fails a window shld come saying "Can;t insert ".. How will I track if the insertion is success or not? Below is the program... use strict; use warnings; use CGI; use DBI; my $cgi = new CGI; print $cgi->header( "text/html" ); print $cgi->start_html( "Welcome" ); my $dbh = DBI->connect("DBI:Pg:dbname=testdb;host=localhost",'po stgres','postgres',{RaiseError=>1,PrintErr or=>1}) or die "Cannot connect to testdb\n"; my $sth=$dbh->prepare("insert into ...

  1. #1

    Default How to track the success of insert

    Hi

    I was trying out some practice examples with DBI and CGI and kind of stuck while doing a comparison

    That is if I could insert successfully into a databse a script window shld come "Success". but when the insert fails
    a window shld come saying "Can;t insert "..

    How will I track if the insertion is success or not? Below is the program...


    use strict;
    use warnings;
    use CGI;
    use DBI;
    my $cgi = new CGI;
    print $cgi->header( "text/html" );
    print $cgi->start_html( "Welcome" );
    my $dbh = DBI->connect("DBI:Pg:dbname=testdb;host=localhost",'po stgres','postgres',{RaiseError=>1,PrintErr
    or=>1})
    or die "Cannot connect to testdb\n";

    my $sth=$dbh->prepare("insert into userinfo values('$fvalue','$lvalue','$email')");
    $sth->execute();
    if($sth)
    {
    print $cgi->p( "<script language=Javascript> alert('Execution Done') </script>" );
    }
    else
    {
    print $cgi->p("<Script language=Javascript> alert('Execution Not Done') </script>" );
    }

    Anish Guest

  2. #2

    Default RE: How to track the success of insert


     

    Suggestion:
    Put your instert inside a transaction like this:

    [snip]

    #begin transaction
    $dbh->begin_work;
    eval{
    #you can decide to combine prepare() and execute() into do()
    $dbh->do( "insert into userinfo values ('$fvalue','$lvalue','$email')" );
    };
    #check if the transaction went ok
    if($){
    $dbh->rollback;
    print $cgi->p("<Script language=Javascript> alert('Execution Not Done') </script>" );
    }
    else{
    $dbh->commit;
    print $cgi->p( "<script language=Javascript> alert('Execution Done') </script>" );
    }


    Tim Bunce (the Auteur of DBI) gave a nice presentation about
    "DBI transactions" that you can find from this link:
    http://search.cpan.org/src/TIMB/DBI_AdvancedTalk_2004/sld054.htm

    Or from
    http://dbi.perl.org (Online Doentation)

    HTH,

    Josť.



    **** DISCLAIMER ****

    "This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above.
    Any use of the information contained herein (including, but not limited to,total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited.
    If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".

    Thank you for your cooperation.

    For further information about Proximus mobile phone services please see ourwebsite at http://www.proximus.be or refer to any Proximus agent.

    NYIMI Guest

  3. #3

    Default RE: How to track the success of insert


     

    Suggestion:
    Put your instert inside a transaction like this:

    [snip]

    #begin transaction
    $dbh->begin_work;
    eval{
    #you can decide to combine prepare() and execute() into do()
    $dbh->do( "insert into userinfo values ('$fvalue','$lvalue','$email')" );
    $dbh->commit;
    };
    #check if the transaction went ok
    if($){
    $dbh->rollback;
    print $cgi->p("<Script language=Javascript> alert('Execution Not Done') </script>" );
    }
    else{
    print $cgi->p( "<script language=Javascript> alert('Execution Done') </script>" );
    }


    Tim Bunce (the Author of DBI) gave a nice presentation
    about "DBI transactions" that you can find from this link:
    http://search.cpan.org/src/TIMB/DBI_AdvancedTalk_2004/sld054.htm

    Or from
    http://dbi.perl.org (Online Doentation)

    HTH,

    Josť.



    **** DISCLAIMER ****

    "This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above.
    Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited.
    If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".

    Thank you for your cooperation.

    For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent.


    --
    To unsubscribe, e-mail: org
    For additional commands, e-mail: org <http://learn.perl.org/> <http://learn.perl.org/first-response>


    NYIMI Guest

Similar Threads

  1. Question Insert from ASP to SQL using recordset data as values in insert statement
    By JasonM in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: June 13th, 05:54 PM
  2. insert success message
    By wee_elks in forum Dreamweaver AppDev
    Replies: 3
    Last Post: May 10th, 03:40 AM
  3. Replies: 3
    Last Post: September 30th, 09:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139