LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Closed Thread
 
Search this Thread
Old 06-12-2005, 06:09 AM   #1
supermyself
LQ Newbie
 
Registered: May 2005
Posts: 17

Rep: Reputation: 0
HELP:perl CGI problem


Here is the HTML source and the corresponding CGI program ,but the CGI program cannot be correctly executed as expected.
If any advice could be given,it would be great!
Thx a lot.

HTML:

<HTML>
<TITLE>vote program</TITLE>
<h1>vote program</h1>
<FORM METHOD="post" ACTION="/cgi-bin/vote.pl">
who do you like better?<br>
<input type="radio" name="idol" value="zhang" checked>A<br>
<input type="radio" name="idol" value="ajiax">B<br>
<input type="radio" name="idol" value="sangbulas">C<br>
<input type="radio" name="idol" value="buck">D<br>
<input type="radio" name="idol" value="guyi">E<br>

<input type="submit" value="execute">
<input type="reset" value="abort">
</form>
query<a href="/cgi-bin/vote.pl?command=view">vote result</a>
</html>

CGI:

#! /usr/bin/perl -wT
print"Content-Type: text/html\n\n";
print"<title>vote</title>";

if($ENV{'REQUEST_METHOD'}eq"POST"){
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
}elsif($ENV{'REQUEST_METHOD'}eq"GET"){
$buffer=$ENV{'QUERY_STIRNG'};
}

@pairs=split(/&/,$buffer);
foreach $pair(@pairs){
($name,$value)=split(/=/,$pair);
$value=~tr/+//;
$value=~s/%([a-f A-F 0-9][a-f A-f 0-9])/pack("C",hex($1))/eg;
$FORM{$name}=$value;}

$filename="/vote.dat";
%NAME=("A","zhang","B","ajiax","C","sangbulas","D","buck","E","guyi");

if($ENV{'REQUEST_METHOD'}eq"POST"){
print"Content-type:text/html\n\n";
print"<title>vote system</title>";
print"<h1>an example of the vote system</h1>";
open(FILE,"<$filename")||die"cannot open the file.please contact with the system manager\n";

for($i=0;$i<2;$i++){
$file[$i]=<FILE>;
$file[$i]=~s/\n$//;
}
close(FILE);

@item=split(/:/,$file[0]);
@vote=split(/:/,$file[1]);

for($i=0;$i<@item;$i++){
if($FORM{'idol'}eq$item[$i]){
$vote[$i]++;
last;
}
}
open(FILE,">filename")||die"Can't Open the file";
$item=join(":",@item);
$vote=join(":",@vote);
pirnt FILE "$item\n";
print FILE "$vote\n";

close (FILE);

print"<h2>you vote for$NAME{$FORM{'idol'}},thans for voting!<h2>";
print"query<a href=\"/cgi-bin/vote.pl?command=viem\">result</a>";

}

if($FORM{'command'}eq"view"){
print "Content-type:text/html\n\n";
print"<title>result</title>";
print"<h1>result</h1>";
open (FILE,"$filename")||die"cannot open the file";

for($i=0;$i<2;$i++){
$file[$i]=<FILE>;
$file[$i]=~s/\n$//;
}
close(FILE);

@item=split(/:/,$file[0]);
@vote=split(/:/,$file[1]);

print"<table border=1>";

for($i=0;$i<@item;$i++){
print"<tr><td>name</td><td>$NAME{$item[$i]}</td><td>count</td>,td>$vote[$i]</td><tr>";

}
print "</table>";
}
 
Old 06-12-2005, 07:14 AM   #2
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
These two posts are on the same issue arent' they

<edit>
Are these your two posts related to the same principle is what I was asking</edit>

Last edited by musicman_ace; 06-12-2005 at 07:17 AM.
 
Old 06-12-2005, 08:34 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,372

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI -PERL Problem!!! lewkh Fedora 3 05-10-2005 12:19 AM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
CGI/Perl problem with SuExec kalbaz Linux - General 2 10-18-2003 06:25 PM
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM
Problem with perl and cgi files JSP Linux - General 1 03-22-2002 08:01 AM


All times are GMT -5. The time now is 01:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration