473,699 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Perl-CGI and MySQL

76 New Member
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 3302
kaioshin00
46 New Member
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 New Member
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,509 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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 Recognized Expert Specialist
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,509 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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,509 Recognized Expert Moderator Specialist
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 New Member
heheheeee....yo u guys are funny.
happy chatting!
Oct 6 '07 #10

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

Similar topics

4
8132
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: ------------------------------------- test3.pl ------------------------------------- print "PERL Hello from Perl! (plain print)<br>\n"; print STDERR "PERL This is text sent to STDERR<br>\n"; $output="PERL Some output:<br>\n"; for ($i=0; $i<5; $i++) {
6
5948
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question is this... is Perl so much better at parsing text files and outputing that we would see a substantial speed increase? We process about 10 million records in flat files a day for reformatting before putting them in a DB. Also, when it comes to...
42
4084
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time. I'm not interested on which language is better in *general*, just for my purpose. My area of research is in CAD algorithms, and I'm sensing the need to resort to something more expedient than C++, bash scripting, or sed scripting.
31
4792
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is great for pattern matching, text processing, and automated testing. Our company is really fixated on risk managnemt and the only way I can do enough testing without working overtime (which some people have ended up doing) is by automating my...
3
3453
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually have two interpreters at the same time. On Red Hat Linux 7.3 with Perl 5.6.1, the attached program segfaults. On Red Hat 9 with Perl 5.8.0, it works perfectly. Save the program code as "test-embed-perl.c" and the build script as "buildte". ...
1
4684
by: Julia Bell | last post by:
I would like to run the same script on two different platforms. The directory in which the script(s) will be stored is common to the two platforms. (I see the same directory contents regardless of which platform I use to access the directory.) Platform 1: perl is installed in /tps/bin/perl. CPAN modules are available Perl is also installed in /usr/bin/perl Platform 1, but the modules are not accessible with this version. Platform...
20
4067
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: li=;
0
9739
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile. I need it to be compiled with threads. Anyone have any wisdom on how best to do this? Here's a transcript of my latest attempt. It's long; you might want to skip to the bottom, where I try "make" and the fatal errors start happening.
13
3258
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt fails in a rather dramatic way, spewing out thousands of "relocation remains"... I'm somewhat lost on what to do next, the documentation that came along with the Perl package is somewhat sparse. Anyone have suggestions? % uname -a
0
8697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8621
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9042
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8891
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.