469,295 Members | 1,928 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,295 developers. It's quick & easy.

Perl-CGI and MySQL

76
Hi guys,
I have a small problem with my Perl-CGI script, and I would appreciate if anyone can help me out with this. I'm trying to get this done in two stages. 1st to get a bunch of info from the web and display it (which is working fine), but the 2nd part is, I want to add some of these info into my MySQL table after viewing them (I don't know how to do in Perl). Right now the script immediately adds values to the MySQL table, before I even click on submit button.
Thanks alot in advance.
Following is the script that I'm trying to write.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl -w
  3. use strict;
  4. use CGI;
  5. use LWP::Simple;
  6. use Bio::DB::SwissProt;
  7. use DBI;
  8.  
  9. my $cgi = new CGI;
  10.  
  11. print $cgi->header() .
  12. $cgi->start_html(   -title => 'Results',
  13.                     -bgcolor => '#6699CC').
  14. # HTML table starts...
  15.         print '<TABLE border="1" cellspacing="0" cellpadding="3" width="80%">' . "\n";
  16. ......
  17. print "<tr><th width='15%'>Entry Name</th><td>" . $id . "</td></tr>\n"; 
  18.         print "<tr><th>Accession</th><td>" . $accession . "</td></tr>\n";
  19.         print "<tr><th>Protein Name</th><td>" . $sequence . "</td></tr>\n";
  20. ......
  21.  
  22. print "<tr><td><INPUT type=\"reset\" name=\"cancel\" value=\"Cancel\"></td>";        print "<td><INPUT type=\"submit\" name=\"update\" value=\"Update\" onsubmit=\"???\"></td></tr>";
  23.  
  24. ....
  25. my $dbh = DBI->connect ("DBI:mysql:database:xxx.xxx.xxx.xxx","root","password") or die "Error: $DBI::errstr\n";
  26.         my $sql = "INSERT INTO table (a, b, c) VALUES ('$accession', '$sequence', '$id')";
  27.         my $in = $dbh->prepare($sql);
  28.         $in->execute;
  29.  
Oct 4 '07 #1
9 2982
I'm a beginner at perl, and have never used it for CGI development, but I think I see your problem -- your code is adding to the database right below displaying them.

You can set up your page as a form


[display values]

<form action="insert.cgi">
<input type = "submit">
</form>


Then, in insert.cgi, you add the values to your mySQL database.

Or something of that nature ... since I've never used perl for CGI :)
Oct 4 '07 #2
idorjee
76
thanks kaioshin00 for your reply.
does anyone know why i can't execute the subroutine like this, and any other ways?:

Expand|Select|Wrap|Line Numbers
  1. print $cgi->button(-name=>'update', -value=>'UPDATE', -onClick=>&update_db);
  2.  
  3. sub update_db{
  4. my $dbh = DBI->connect ("DBI:mysql:......);
  5. my $sql = "INSERT INTO .......
  6. }
  7.  
Appreciate it!
Oct 5 '07 #3
numberwhun
3,503 Expert Mod 2GB
thanks kaioshin00 for your reply.
does anyone know why i can't execute the subroutine like this, and any other ways?:

Expand|Select|Wrap|Line Numbers
  1. print $cgi->button(-name=>'update', -value=>'UPDATE', -onClick=>&update_db);
  2.  
  3. sub update_db{
  4. my $dbh = DBI->connect ("DBI:mysql:......);
  5. my $sql = "INSERT INTO .......
  6. }
  7.  
Appreciate it!
Can we please learn how to use code tags?! There is a sample in the REPLY GUIDELINES to the right of the message window when posting. Please read it and follow the example.

Thank you!

-Moderator
Oct 5 '07 #4
KevinADC
4,059 Expert 2GB
thanks kaioshin00 for your reply.
does anyone know why i can't execute the subroutine like this, and any other ways?:

Expand|Select|Wrap|Line Numbers
  1. print $cgi->button(-name=>'update', -value=>'UPDATE', -onClick=>&update_db);
  2.  
  3. sub update_db{
  4. my $dbh = DBI->connect ("DBI:mysql:......);
  5. my $sql = "INSERT INTO .......
  6. }
  7.  
Appreciate it!
onClick is to initiate javascript code, not perl code.
Oct 5 '07 #5
KevinADC
4,059 Expert 2GB
Can we please learn how to use code tags?! There is a sample in the REPLY GUIDELINES to the right of the message window when posting. Please read it and follow the example.

Thank you!

-Moderator
Looks like MIller left you hanging. Give yourself a break Jeff, don't worry about the code tags, what's Mary gonna do, fire you? ;)
Oct 5 '07 #6
numberwhun
3,503 Expert Mod 2GB
Looks like MIller left you hanging. Give yourself a break Jeff, don't worry about the code tags, what's Mary gonna do, fire you? ;)
Nah, not in my nature. I am too anal to let it go. :-)

What did happen to Miller? I haven't seen him. Haven't had a response to PM's. Mary says she saw him online but no hide nor hair.
Oct 5 '07 #7
KevinADC
4,059 Expert 2GB
Nah, not in my nature. I am too anal to let it go. :-)

What did happen to Miller? I haven't seen him. Haven't had a response to PM's. Mary says she saw him online but no hide nor hair.
hehehe...

I have no clue what happend to M. I hope he's on a tropical island dancing naked with the beautiful natives. I'll drop him an email and see if he responds. He might have just got burned out with the whole forum posting stuff, it happens.
Oct 5 '07 #8
numberwhun
3,503 Expert Mod 2GB
hehehe...

I have no clue what happend to M. I hope he's on a tropical island dancing naked with the beautiful natives. I'll drop him an email and see if he responds. He might have just got burned out with the whole forum posting stuff, it happens.
True, it certainly does! Let me know if you hear from him. Just want to make sure he's ok.
Oct 5 '07 #9
idorjee
76
heheheeee....you guys are funny.
happy chatting!
Oct 6 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Mark Wilson CPU | last post: by
6 posts views Thread by John Smith | last post: by
42 posts views Thread by Fred Ma | last post: by
31 posts views Thread by surfunbear | last post: by
1 post views Thread by Julia Bell | last post: by
20 posts views Thread by Xah Lee | last post: by
reply views Thread by Kirt Loki Dankmyer | last post: by
13 posts views Thread by Otto J. Makela | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.