/    Sign up×
Community /Pin to ProfileBookmark

Making a PhP Color Code Test

I am trying to make a PhP color code test and I can not get it just right. Right now all I can get it to do is post the value. How I want it to work is:

There is 4 questions (on my real test there will be 45) with 4 different options to choose from. I would like the PhP to be able to determine which option was chosen for each question then assign a value to the option so in the end of the test it will be able to add each individual option for each question together… Example:

Q1 proactive nurturing objective insightful
Q2 indecisive arrogant a perfectionist poor follow-through
Q3 enthusiastic kind caring productive
Q4 relentless suspicious indifferent naive

Peron takes test and for Q1 chooses “proactive” then on Q2 chooses “indecisive” Q3 chooses “kind” Q4 chooses “naive”

I want the results to show as Reds (or column 1)=2
Blues (or Column 2) =1
Yellows (or Column 3)=0
White (or Column 4)=1

Here is a sample of my code that I have already wrote.

<?php
function add($a =0, $b = 0, $c =0, $d =0)
{
return ($a + $b + $c + $d);
}
$r1 = $_POST[‘r1’];
$r2 = $_
POST[‘r2’];
$r3 = $_POST[‘r3’];
$r4 = $_
POST[‘r4’];
?>

<form action=”results.php” method=”post”>

<table>
<tr>
<li><ul>
<td><label title=”Definition: Acting positive, pre-emptive in resolving problems”><input TYPE=”radio” VALUE=”1″ NAME=”r1″> proactive</label></td>
<td><label title=”Definition: Caring, concerned, attentive”><input TYPE=”radio” VALUE=”1″ NAME=”r1″> nurturing</label></td>
<td><label title=”Definition: Displaying clear and unbiased judgment, fair”><input TYPE=”radio” VALUE=”1″ NAME=”r1″> objective</label></td>
<td><label title=”Definition: Being perceptive of subtle ideas or concepts”><input TYPE=”radio” VALUE=”1″ NAME=”r1″> insightful</label></td>
</ul></li>
</tr>
</table>

<table><tr>
<li> <ul>
<td><label title=”Definition: Uncertain, hesitant, ambivalent”><input TYPE=”radio” VALUE=”1″ NAME=”r2″> indecisive</label></td>
<td><label title=”Definition: Puffed up, conceited, air of superiority”><input TYPE=”radio” VALUE=”1″ NAME=”r2″> arrogant</label></td>
<td><label title=”Definition: Insistent on eliminating all flaws and error”><input TYPE=”radio” VALUE=”1″ NAME=”r2″> a perfectionist</label></td>
<td><label title=”Definition: Not seeing things through to the end”><input TYPE=”radio” VALUE=”1″ NAME=”r2″> poor follow-through</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title=”Definition: Eager, spirited, energetic”><input TYPE=”radio” VALUE=”1″ NAME=”r3″> enthusiastic</label></td>
<td><label title=”Definition: Gentle, pleasant, considerate”><input TYPE=”radio” VALUE=”1″ NAME=”r3″> kind</label></td>
<td><label title=”Definition: Feeling and exhibiting concern and empathy for others”><input TYPE=”radio” VALUE=”1″ NAME=”r3″> caring</label></td>
<td><label title=”Definition: Efficient, resourceful, constructive”><input TYPE=”radio” VALUE=”1″ NAME=”r3″> productive</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title=”Definition: Unyielding in severity or strictness”><input TYPE=”radio” VALUE=”1″ NAME=”r4″> relentless</label></td>
<td><label title=”Definition: Distrustful, skeptical, wary”><input TYPE=”radio” VALUE=”1″ NAME=”r4″> suspicious</label></td>
<td><label title=”Definition: Apathetic, emotionally detached”><input TYPE=”radio” VALUE=”1″ NAME=”r4″> indifferent</label></td>
<td><label title=”Definition: Trusting, gullible, unsuspecting”><input TYPE=”radio” VALUE=”1″ NAME=”r4″> na&iuml;ve</label></td>
</ul></li>
</tr></table>
<input type=”submit” value=”Calculate values”/>
</form>
Answer : <?php echo add($r1,$r2,$r3,$r4); ?>

Right now it only adds all the columns together so I can not separate out the Columns and tell people what there answer are.

I am sorry this is so long. If this does not make sense please let me know and I will try to explain it better.

Please and thank you for any help

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@tirnaAug 09.2010 — At the moment the value of each option for your raduo buttons is set to 1.

If I understand you correctly, all you need to do is set the values of all the first option radio buttons to 2, the second option buttons to 1, the 3rd option buttons to 0 and the 4th button options to 1.

Only the value of the checked radio button is sent to results.php and then you can do whatever you need to do with the sent values
Copy linkTweet thisAlerts:
@DRAauthorAug 09.2010 — I tried messing around with what you said but I still am having problems with getting each one to be detected. I need to know on each question wither they chose the first answer or the second answer or third answer or the fourth. Then I need to be able to add all the first answers they chose together and then the second answers they chose together and then the third answers they chose together and then the fourth answers they chose together..

Sorry I just am really confused on this one!
Copy linkTweet thisAlerts:
@tirnaAug 09.2010 — ok, I slightly misunderstood you original problem.

I would do something like this.

For each question (each set of radio buttons) I would assign a value of 1 to 4 for each set of 4 radio buttons which represent which option was selected.

Then in results.php you can add whatever values you like to variables containing cumulative totals of values for each question.

$r1 - $r4 will store the option number selected for each question.

[code=php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action="results.php" method="post">
<table>
<tr>
<li><ul>
<td><label title="Definition: Acting positive, pre-emptive in resolving problems"><input TYPE="radio" VALUE="1" NAME="r1"> proactive</label></td>
<td><label title="Definition: Caring, concerned, attentive"><input TYPE="radio" VALUE="2" NAME="r1"> nurturing</label></td>
<td><label title="Definition: Displaying clear and unbiased judgment, fair"><input TYPE="radio" VALUE="3" NAME="r1"> objective</label></td>
<td><label title="Definition: Being perceptive of subtle ideas or concepts"><input TYPE="radio" VALUE="4" NAME="r1"> insightful</label></td>
</ul></li>
</tr>
</table>
<table><tr>
<li> <ul>
<td><label title="Definition: Uncertain, hesitant, ambivalent"><input TYPE="radio" VALUE="1" NAME="r2"> indecisive</label></td>
<td><label title="Definition: Puffed up, conceited, air of superiority"><input TYPE="radio" VALUE="2" NAME="r2"> arrogant</label></td>
<td><label title="Definition: Insistent on eliminating all flaws and error"><input TYPE="radio" VALUE="3" NAME="r2"> a perfectionist</label></td>
<td><label title="Definition: Not seeing things through to the end"><input TYPE="radio" VALUE="4" NAME="r2"> poor follow-through</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Eager, spirited, energetic"><input TYPE="radio" VALUE="1" NAME="r3"> enthusiastic</label></td>
<td><label title="Definition: Gentle, pleasant, considerate"><input TYPE="radio" VALUE="2" NAME="r3"> kind</label></td>
<td><label title="Definition: Feeling and exhibiting concern and empathy for others"><input TYPE="radio" VALUE="3" NAME="r3"> caring</label></td>
<td><label title="Definition: Efficient, resourceful, constructive"><input TYPE="radio" VALUE="4" NAME="r3"> productive</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Unyielding in severity or strictness"><input TYPE="radio" VALUE="1" NAME="r4"> relentless</label></td>
<td><label title="Definition: Distrustful, skeptical, wary"><input TYPE="radio" VALUE="2" NAME="r4"> suspicious</label></td>
<td><label title="Definition: Apathetic, emotionally detached"><input TYPE="radio" VALUE="3" NAME="r4"> indifferent</label></td>
<td><label title="Definition: Trusting, gullible, unsuspecting"><input TYPE="radio" VALUE="4" NAME="r4"> na&iuml;ve</label></td>
</ul></li>
</tr></table>
<input type="submit" value="Calculate values"/>
</form>

</body>
</html>
[/code]


[B][U]results.php[/U][/B]

[B][/B]
[code=php]
<?php

$r1 = $_POST['r1'];
$r2 = $_POST['r2'];
$r3 = $_POST['r3'];
$r4 = $_POST['r4'];

echo 'r1 = '.$r1.'<br />';
echo 'r2 = '.$r2.'<br />';
echo 'r3 = '.$r3.'<br />';
echo 'r4 = '.$r4.'<br />';
?>
[/code]
Copy linkTweet thisAlerts:
@DRAauthorAug 09.2010 — Thank you for your help! I really am a novice with PhP so I still am having some problems. I am sorry but how do I get them to add the values together?

The VALUE in the form are like this <input TYPE="radio" VALUE="1" NAME="r1">

VALUE 1 will equal Reds

VALUE 2 will equal Blues

VALUE 3 will equal Yellows

VALUE 4 will equal Whites

So if I take the test right not it will show up like this

(

r1=1

r2=1

r3=1

r4=2

r5=4

r6=3

r7=1

r8=1

r9=1

)

But I need it to add the the number of times a VALUE was selected....

So they chose the answer with the VALUE 1(red) 6 different times so I need the out put to say 6 reds

So they chose the answer with the VALUE 2(blue) 1 time so I need the out put to say 1 blue

So they chose the answer with the VALUE 3(Yellow) 1 time so I need the out put to say 1 Yellow


So they chose the answer with the VALUE 2(White) 1 time so I need the out put to say 1 white


[code=php]<?php

$r1 = $_POST['r1'];
$r2 = $_POST['r2'];
$r3 = $_POST['r3'];
$r4 = $_POST['r4'];
$r5 = $_POST['r5'];
$r6 = $_POST['r6'];
$r7 = $_POST['r7'];
$r8 = $_POST['r8'];
$r9 = $_POST['r9'];

echo 'r1 = '.$r1.'<br />';
echo 'r2 = '.$r2.'<br />';
echo 'r3 = '.$r3.'<br />';
echo 'r4 = '.$r4.'<br />';
echo 'r5 = '.$r5.'<br />';
echo 'r6 = '.$r6.'<br />';
echo 'r7 = '.$r7.'<br />';
echo 'r8 = '.$r8.'<br />';
echo 'r9 = '.$r9.'<br />';
?> [/code]


[code=html]

<form action="results.php" method="post">
<table>
<tr>
<li><ul>
<td><label title="Definition: Acting positive, pre-emptive in resolving problems"><input TYPE="radio" VALUE="1" NAME="r1"> proactive</label></td>
<td><label title="Definition: Caring, concerned, attentive"><input TYPE="radio" VALUE="2" NAME="r1"> nurturing</label></td>
<td><label title="Definition: Displaying clear and unbiased judgment, fair"><input TYPE="radio" VALUE="3" NAME="r1"> objective</label></td>
<td><label title="Definition: Being perceptive of subtle ideas or concepts"><input TYPE="radio" VALUE="4" NAME="r1"> insightful</label></td>
</ul></li>
</tr>
</table>

<table><tr>
<li> <ul>
<td><label title="Definition: Uncertain, hesitant, ambivalent"><input TYPE="radio" VALUE="1" NAME="r2"> indecisive</label></td>
<td><label title="Definition: Puffed up, conceited, air of superiority"><input TYPE="radio" VALUE="2" NAME="r2"> arrogant</label></td>
<td><label title="Definition: Insistent on eliminating all flaws and error"><input TYPE="radio" VALUE="3" NAME="r2"> a perfectionist</label></td>
<td><label title="Definition: Not seeing things through to the end"><input TYPE="radio" VALUE="4" NAME="r2"> poor follow-through</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Eager, spirited, energetic"><input TYPE="radio" VALUE="1" NAME="r3"> enthusiastic</label></td>
<td><label title="Definition: Gentle, pleasant, considerate"><input TYPE="radio" VALUE="2" NAME="r3"> kind</label></td>
<td><label title="Definition: Feeling and exhibiting concern and empathy for others"><input TYPE="radio" VALUE="3" NAME="r3"> caring</label></td>
<td><label title="Definition: Efficient, resourceful, constructive"><input TYPE="radio" VALUE="4" NAME="r3"> productive</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Unyielding in severity or strictness"><input TYPE="radio" VALUE="1" NAME="r4"> relentless</label></td>
<td><label title="Definition: Distrustful, skeptical, wary"><input TYPE="radio" VALUE="2" NAME="r4"> suspicious</label></td>
<td><label title="Definition: Apathetic, emotionally detached"><input TYPE="radio" VALUE="3" NAME="r4"> indifferent</label></td>
<td><label title="Definition: Trusting, gullible, unsuspecting"><input TYPE="radio" VALUE="4Z" NAME="r4"> na&iuml;ve</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Calm, quiet, serene, gentle"><input TYPE="radio" VALUE="1" NAME="r5"> peaceful</label></td>
<td><label title="Definition: Living in the moment, lighthearted, worry-free"><input TYPE="radio" VALUE="2" NAME="r5"> carefree</label></td>
<td><label title="Definition: Conclusive, ready to act now"><input TYPE="radio" VALUE="3" NAME="r5"> decisive</label></td>
<td><label title="Definition: Dependable, faithful, reliable"><input TYPE="radio" VALUE="4" NAME="r5"> loyal</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Quietly inflexible, obstinate"><input TYPE="radio" VALUE="1" NAME="r6"> silently stubborn</label></td>
<td><label title="Definition: Inclined to feel concerned or anxious"><input TYPE="radio" VALUE="2" NAME="r6"> worry prone</label></td>
<td><label title="Definition: Speaking before others are finished"><input TYPE="radio" VALUE="3" NAME="r6"> an interrupter</label></td>
<td><label title="Definition: Excessively preoccupied with ideas,people, emotions, and/or behavior"><input TYPE="radio" VALUE="4" NAME="r6"> obsessive</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Friendly, outgoing, displaying "people skills""><input TYPE="radio" VALUE="1" NAME="r7"> sociable</label></td>
<td><label title="Definition: Direct, to the point, determined"><input TYPE="radio" VALUE="2" NAME="r7"> assertive</label></td>
<td><label title="Definition: Desiring close relationships with others"><input TYPE="radio" VALUE="3" NAME="r7"> intimate</label></td>
<td><label title="Definition: Not prejudiced or disregarding of individual merit"><input TYPE="radio" VALUE="4" NAME="r7"> non-discriminate</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Self deprecating, finding fault with self"><input TYPE="radio" VALUE="1" NAME="r8"> self-critical</label></td>
<td><label title="Definition: Pushy, overbearing, dictatorial"><input TYPE="radio" VALUE="2" NAME="r8"> bossy</label></td>
<td><label title="Definition: Easily distracted, unable to concentrate"><input TYPE="radio" VALUE="3" NAME="r8"> unfocused</label></td>
<td><label title="Definition: Preferring quiet path of least resistance; avoiding disagreement"><input TYPE="radio" VALUE="4" NAME="r8"> avoids conflict</label></td>
</ul></li>
</tr></table>
<table><tr>
<li> <ul>
<td><label title="Definition: Bringing a sound sense of practicality"><input TYPE="radio" VALUE="1" NAME="r9"> voice of reason</label></td>
<td><label title="Definition: Adjusting readily to changing conditions"><input TYPE="radio" VALUE="2" NAME="r9"> flexible</label></td>
<td><label title="Definition: Motivated to do or to make things happen"><input TYPE="radio" VALUE="3" NAME="r9"> action-oriented</label></td>
<td><label title="Definition: Complex reasoning, organized, careful"><input TYPE="radio" VALUE="4" NAME="r9"> analytical</label></td>
</ul></li>
</tr></table>

<input type="submit" value="Calculate values"/>
</form>[/code]
Copy linkTweet thisAlerts:
@DRAauthorAug 12.2010 — I Know that I am asking a lot and do not have much understanding of PhP but I really could use some help with this and really appreciate it very much.... Thanks
×

Success!

Help @DRA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...