I am trying to create a survey that displays only one question at a time. i have gotten it to show and store the question, but i cannot get to the next question in the survey. i know that once i get to the next question in the survey i can get back to the previous one, i have been stuck on this for 2 weeks. if anyone could help that would be great.

here is my code.

#! c:/wamp/bin/perl/bin/perl.exe
use CGI;
use CGI qw(:standard);
use DBI; 
$q = new CGI;

$q1 = $q->param('q1');
$q2 = $q->param('q2');
$q3 = $q->param('q3');
$q4 = $q->param('q4');

$myFav;
$var;

@counter=("<table align='right' border='1'><tr><td>0%</td></tr></table><br>\n","1");
@questions = ("1.Enter Your Name", "2.Did you find the information included within this web site useful?", 
"3. Is the web site easey to Navigate?", "4. Were you able to find the information you were looking for?",
"5.What other information you would like to include in the web site?","6.What suggestions you might have for our web site improvement?");
$sizeQ = @questions;
$sizeC = @counter;
$j = 0;
&header;
&counter;
sub header
{#print the header for survey page
print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<title> My Survey </title></head>\n";
print "<body bgcolor=\#8989ff\>\n";
}

sub counter{
if($counter==0)
{
&firstQuestion;
$counter = $counter +1;
}
elsif($counter==1)
{
&secondQuestion;
$counter = $counter +1;
}
elsif($counter==2)
{
&thirdQuestion;
$counter = $counter +1;
}
elsif($counter==3)
{
&forthQuestion;
$counter = $counter +1;
}
}

sub firstQuestion
{
print @counter[0];
print "<h1 margin-top='3em' align='center'>\n";
print @questions[0]; 
print "<hr size='1' width='98%' align='center' color='#FFFFFF'/>\n";
print "<form action='survey.cgi' method=GET >\n";
print "<table align=center border=2>\n";
print "<tr><td><input type=text size=30 maxlength=20 name=q1 value=''\n>
       </td></tr>\n";
print "<tr><td colspan=2 align=center> <input type='submit' value='Next'\n>
       </td></tr>\n";
print "</table>\n";
}

sub secondQuestion
{
print @counter[1];
print "<h1 margin-top='3em' align='center'>\n";
print @questions[1]; 
print "<hr size='1' width='98%' align='center' color='#FFFFFF'/>\n";
print "<form action='survey.cgi' method=GET >\n";
print "<table align=center border=2>\n";
print "<tr><td><input type=text size=30 maxlength=20 name=q2 value=''\n>
       </td></tr>\n";
print "<tr><td colspan=2 align=center> <input type='submit' value='Next'\n>
       </td></tr>\n";
print "</table>\n";
}

sub thirdQuestion
{
print @counter[3];
print "<h1 margin-top='3em' align='center'>\n";
print @questions[3]; 
print "<hr size='1' width='98%' align='center' color='#FFFFFF'/>\n";
print "<form action='survey.cgi' method=GET >\n";
print "<table align=center border=2>\n";
print "<tr><td><input type=text size=30 maxlength=20 name=q3 value=''\n>
       </td></tr>\n";
print "<tr><td colspan=2 align=center> <input type='submit' value='Next'\n>
       </td></tr>\n";
print "</table>\n";
}

sub forthQuestion
{
print @counter[4];
print "<h1 margin-top='3em' align='center'>\n";
print @questions[4]; 
print "<hr size='1' width='98%' align='center' color='#FFFFFF'/>\n";
print "<form action='survey.cgi' method=GET >\n";
print "<table align=center border=2>\n";
print "<tr><td><input type=text size=30 maxlength=20 name=q4 value=''\n>
       </td></tr>\n";
print "<tr><td colspan=2 align=center> <input type='submit' value='Next'\n>
       </td></tr>\n";
print "</table>\n";
}
print $q1;
print $q2;

please help.

you'll either have to store the form contents in cookies, sessions or in hidden form feilds and since you only have 3 questions the hidden will be the less work and faster..
as far as jumping back and forth you need to add an element to the url

script.pl?current=quest1&next=quest2

then when the user clicks the next button youll need to update the url to reflect the correct page.

also array slices are accessed like $questions[0];
`

you need to make sure you use these following modules

use strict;
use warnings;

`

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.