473,748 Members | 2,353 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 3307
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
8134
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
5950
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
4107
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
4801
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
3456
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
4688
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
4072
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
9744
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
3261
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
8831
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
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9376
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...
0
9249
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...
0
8245
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
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...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.