vigiw Posted July 5, 2008 Share Posted July 5, 2008 Hello, I've tried creating a form for a "quiz" (not a right-wrong quiz, but one which scores numbers of values for each selection for a specific result) using Javascript, but it didn't work out. I was wondering how, using the same form, I could go about doing this in PHP (if possible). I gave up on Javascript because it kept showing "NaN" for the calculated score, even though every value is a number, but some are negative (e.g. -5 for one value; 3 for another). Any help for this would certainly be appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/113392-add-radio-form-values-with-php/ Share on other sites More sharing options...
vigiw Posted July 6, 2008 Author Share Posted July 6, 2008 Ok... I've created a code for my need as described above, and the form's submit button will POST to my php file. But when I submit, the PHP page comes up blank. Here's the code: <?php $q1 = $_POST['q1']; $q2 = $_POST['q2']; $q3 = $_POST['q3']; $q4 = $_POST['q4']; $q5 = $_POST['q5']; $q6 = $_POST['q6']; $q7 = $_POST['q7']; $q9 = $_POST['q9']; $q13 = $_POST['q13']; $q17 = $_POST['q17']; $q18 = $_POST['q18']; $q19 = $_POST['q19']; $q8 = $_POST['q8']; $q10 = $_POST['q10']; $q11 = $_POST['q11']; $q12 = $_POST['q12']; $q14 = $_POST['q14']; $q15 = $_POST['q15']; $q16 = $_POST['q16']; $soc = $q1 + $q2 + $q3 + $q4 + $q5 + $q6 + $q7 + $q9 + $q13 + $q17 + $q18 + $q19; echo "You are" $soc; "% Socially" if ($var >= 50) echo " Liberal<br>"; else echo " Conservative<br>"; $ec = $q8 + $q10 + $q11 + $q12 + $q14 + $q15 + $q16; echo "You are" $ec; "% Fiscally (Economcially)" if ($var >= 50) echo " Liberal<br>"; else echo " Conservative<br>"; ?> Any ideas? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/113392-add-radio-form-values-with-php/#findComment-582626 Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 <?php $q1 = $_POST['q1']; $q2 = $_POST['q2']; $q3 = $_POST['q3']; $q4 = $_POST['q4']; $q5 = $_POST['q5']; $q6 = $_POST['q6']; $q7 = $_POST['q7']; $q9 = $_POST['q9']; $q13 = $_POST['q13']; $q17 = $_POST['q17']; $q18 = $_POST['q18']; $q19 = $_POST['q19']; $q8 = $_POST['q8']; $q10 = $_POST['q10']; $q11 = $_POST['q11']; $q12 = $_POST['q12']; $q14 = $_POST['q14']; $q15 = $_POST['q15']; $q16 = $_POST['q16']; $soc = $q1 + $q2 + $q3 + $q4 + $q5 + $q6 + $q7 + $q9 + $q13 + $q17 + $q18 + $q19; echo "You are $soc% Socially"; if ($var >= 50) { echo " Liberal<br>"; } else { echo " Conservative<br>"; } $ec = $q8 + $q10 + $q11 + $q12 + $q14 + $q15 + $q16; echo "You are $ec% Fiscally (Economically)"' if ($var >= 50) { echo " Liberal<br>"; } else echo " Conservative<br>"; } ?> That should work. You messed up the echo statements with the variables in them. Link to comment https://forums.phpfreaks.com/topic/113392-add-radio-form-values-with-php/#findComment-582629 Share on other sites More sharing options...
marcus Posted July 6, 2008 Share Posted July 6, 2008 $var is not defined. if($soc >= 50){ Link to comment https://forums.phpfreaks.com/topic/113392-add-radio-form-values-with-php/#findComment-582650 Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 Nice catch. Link to comment https://forums.phpfreaks.com/topic/113392-add-radio-form-values-with-php/#findComment-582651 Share on other sites More sharing options...
vigiw Posted July 6, 2008 Author Share Posted July 6, 2008 Ok thanks everyone! Link to comment https://forums.phpfreaks.com/topic/113392-add-radio-form-values-with-php/#findComment-582723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.