Jump to content

Add Radio Form Values with PHP


vigiw

Recommended Posts

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.