Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form creation submit button

Status
Not open for further replies.

lilkal

Programmer
Nov 20, 2008
7
0
0
US
hi..i am trying to create a form having text field,checkboxes,radio buttons and submit reset buttons.
I need to search my database for the given word when the submit button is clicked.
I was able to create the form but i dont know how to pass the word the user entered in order to check the database.Nothing happens when submit is pressed.Here is the db_search.cgi code i used..


#!/usr/local/bin/perl

use CGI::Carp qw(fatalsToBrowser);
use CGI;
use DBI;
my $cgi=new CGI;
print $cgi->header('text/html'),$cgi->start_html(-title=>'students');
print $cgi->center("GENOMES");
$cgi->start_form($method='get',$action='/home/ma/503.01/masc0100/public_html/db_search.cgi');
print $cgi->p("enter the protein accession number");
print $cgi->textfield($name='querry');
print $cgi->p();
print $cgi->br();
print $cgi->p("select name");
print $cgi->popup_menu($name='popup',$values=['a','b','c','d'],$default='a');
print $cgi->p();
print $cgi->br();
print $cgi->p("enter strand");
print $cgi->radio_group($name='radio',$label=['-1','1','0']);
print $cgi->p();
print $cgi->br();
print $cgi->p("select fields to be retrieved");
print $cgi->checkbox($name='accesion number',$value='acc no');
print $cgi->checkbox($name='proteins in the sequence',$value='pacc nos');
print $cgi->checkbox($name='sequence length',$value='seq length');
print $cgi->checkbox($name='sequence',$value='seq');
print $cgi->checkbox($name='function',$value='fnc');
print $cgi->checkbox($name='aliases',$value='aliases');
print $cgi->p();
print $cgi->br();
print $cgi->submit($name='search',$value='submit');
print $cgi->reset();
$cgi->end_form();
$cgi->end_html();
 
On the top use the strict and warning pragmas.

use strict;
use warnings;

Why are you defining form directives as vars? i.e $action, $method, $name?

Take a look at the CGI module and you'll see there are quite a few errors that need to be fixed.
 
i tried to define the form directives normally like name='querry'
and i got this error message:
Can't modify constant item in scalar assignment at db_search.cgi line 11, near "'querry')"
So i defined it as a var and got the output right.
But i dint actually try to use the name later on in my program..Is there some other way in which i can define them normally?
 
So we can assume you are defining your variables like $name and $action, and $method, and etc, but you didn't show that in the code you posted?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
hii..i actually modified the code this way..

#!/usr/local/bin/perl

use CGI::Carp qw(fatalsToBrowser);
use CGI;
use DBI;
my $cgi=new CGI;
print $cgi->header('text/html'),$cgi->start_html(-title=>'students');
print $cgi->center("GENOMES");
$cgi->start_form(-method=>'get',-action=>'/home/ma/503.01/masc0100/public_html/db_search.cgi');
print $cgi->p("enter the protein accession number");
print $cgi->textfield(-name=>'querry');
print $cgi->p();
print $cgi->br();
print $cgi->p("select name");
$i=0;
my $dbh=DBI->connect('DBI:mysql:hostname=rohan.sdsu.edu:database=masc0100','masc0100','Xt2mVeq');
$exc=$dbh->prepare("select distinct name from master");
$exc->execute()||die $dbh->errstr;
@results=$exc->fetchrow_array();
@arr=@results;
print $cgi->popup_menu(-name=>'popup',-values=>\@arr);
print $cgi->p();
print $cgi->br();
print $cgi->p("enter strand");
print $cgi->radio_group(-name=>'radio',-values=>['-1','1','0']);
print $cgi->p();
print $cgi->br();
print $cgi->p("select fields to be retrieved");
print $cgi->checkbox(-name=>'accesion number',-value=>'acc no');
print $cgi->checkbox(-name=>'proteins in the sequence',-value=>'pacc nos');
print $cgi->checkbox(-name=>'sequence length',-value=>'seq length');
print $cgi->checkbox(-name=>'sequence',-value=>'seq');
print $cgi->checkbox(-name=>'function',-value=>'fnc');
print $cgi->checkbox(-name=>'aliases',-value=>'aliases');
print $cgi->p();
print $cgi->br();
print $cgi->submit(-name=>'search',-value=>'submit');
print $cgi->reset();
$cgi->end_form();
$cgi->end_html();

now the ouptut of this code gives a pop up menu with only one entry..it is only taking the first distinct name from the table 'master'..
i need to get all the distinct names from the table..
i dont know where it went wrong..i think its the part where i copied the results of the query into another array...please help me out with this..
 
hii...thanx guyzz...
got it!!!

i replaced

@results=$exc->fetchrow_array();
@arr=@results;

with

$i=0;
while(@results=$exc->fetchrow_array())
{
$arr[$i]=$results[0];
$i+=1;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top