Hey there!
I'm trying to put together a multi-page survey that writes the result of each survey page (= one section of the survey) to a text file. Then at the end of the survey it is supposed to read the totals from each section and read & display a text block according to the achieved value.
what I'm having trouble with, and this has me totally stumped, is that I can't seem to get my script "survey01_scr.php" to accurately calculate the totals for each survey page/section.
Here's how it's supposed to work:
- user fills in form on page 1 (survey01.php)
- the form calls the first script (survey01_scr.php) calculates everything and writes the results to two text files.
- the script (survey01_scr.php) forwards the user to the next page
Any ideas as to why my script seemingly adds up question1 - question3 only (instead of question1 - question4) would be greatly appreciated 🙂
thanks for your help,
kubik
This is the form on my page "survey01.php":
<form name="section01" method="get" action="scripts/survey01_scr.php" onsubmit="return validateForm(this)">
question01
<input type="radio" name="s1q01" value="10">
<input type="radio" name="s1q01" value="0">
question02
<input type="radio" name="s1q02" value="6">
<input type="radio" name="s1q02" value="0">
question03
<input type="radio" name="s1q03" value="8">
<input type="radio" name="s1q03" value="0">
question04
<input type="radio" name="s1q04" value="6">
<input type="radio" name="s1q04" value="0">
<input type="hidden" name="uid" value="<? echo $uid; ?>">
<input type="hidden" name="opt" value="<? echo $opt; ?>">
</form>
This is my "survey01_scr.php":
<?php
//part 1 - get $uid and $opt
//
$_GET['uid'];
$_GET['opt'];
//
//part 2 - calculate total points for section
//
$s1 = $s1q01 + $s1q02 + $s1q03 + s1q04;
//
//part 3 - open "user_$uid.txt", write section results, close file
//
$filename = "../user_results/user_$uid.txt";
$handle = fopen ($filename, "a+");
fwrite ($handle, "$s1q01"."\n"."$s1q02"."\n"."$s1q03"."\n"."$s1q04"."\n"."$s1"." (=total section 1)"."\n"."\n");
fclose ($handle);
//
//part 4 - generate new file "user_$uid_s1.txt", write "$s1", close file
//
$filename1 = "../user_results/user_"."$uid"."_s1.txt";
$handle1 = fopen ($filename1, "a");
fwrite ($handle1, "$s1");
fclose ($handle1);
//
//part 5 - forward user to next page, include user id ($uid) and option ($opt)
//
header ("Location: ../survey02.php?uid=$uid&opt=$opt");
?>
And this is the output written to the file "user_$uid.txt":
survey option 1 - automated
10
6
8
6
24 (=total section 1)