/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Calculate results on same page?

Hi all! I’m putting together a simple PHP quiz. I’m a noob with PHP but so far it’s functioning properly. What it does is the user selects several words (hidden checkboxes) and each of those words relates to a category. Every time one of the words is selected a value of 1 is added to it’s category. When the complete button is pushed you’re taken to the results page which displays the totals for each category. [URL=”http://mindfulmoneycoaching.com/testquiz/money_quiz2.php”]Demo[/URL]

However I’d like the results to be shown on the same page. I’ve been trying to set that up [URL=”http://mindfulmoneycoaching.com/testquiz/money_quiz.php”]on this page[/URL]. I’m doing something wrong though and I can’t figure out what. It’s not displaying any results. I’d appreciate any pointers!

This is at the very top of my page:

[code=php]<?php if(isset($_POST[‘calculate’])){

$innocent = 0;
if ($_POST[‘anxious’] == ‘yes’)
$innocent++;
if ($_POST[‘trusting’] == ‘yes’)
$innocent++;
if ($_POST[‘feels_powerless’] == ‘yes’)
$innocent++;
if ($_POST[‘fearful’] == ‘yes’)
$innocent++;
if ($_POST[‘indecisive’] == ‘yes’)
$innocent++;
if ($_POST[‘financially_dependant’] == ‘yes’)
$innocent++;
if ($_POST[‘happy_go_lucky’] == ‘yes’)
$innocent++;
if ($_POST[‘seeks_security’] == ‘yes’)
$innocent++;
if ($_POST[‘non_confrontational’] == ‘yes’)
$innocent++;
if ($_POST[‘represses_feelings_and_beliefs’] == ‘yes’)
$innocent++;

$victim = 0;
if ($_POST[‘prone_to_blame’] == ‘yes’)
$victim++;
if ($_POST[‘highly_emotional’] == ‘yes’)
$victim++;
if ($_POST[‘lives_in_past’] == ‘yes’)
$victim++;
if ($_POST[‘financially_irrisponsible’] == ‘yes’)
$victim++;
if ($_POST[‘seeks_rescue’] == ‘yes’)
$victim++;
if ($_POST[‘feels_powerless’] == ‘yes’)
$victim++;
if ($_POST[‘unforgiving’] == ‘yes’)
$victim++;
if ($_POST[‘addictive’] == ‘yes’)
$victim++;
if ($_POST[‘self_fulfilling_prophecy’] == ‘yes’)
$victim++;
if ($_POST[‘long_suffering’] == ‘yes’)
$victim++;
if ($_POST[‘passive_aggressive’] == ‘yes’)
$victim++;
if ($_POST[‘resentful’] == ‘yes’)
$victim++;
if ($_POST[‘fearful’] == ‘yes’)
$victim++;

$warrior = 0;
if ($_POST[‘powerful’] == ‘yes’)
$warrior++;
if ($_POST[‘driven’] == ‘yes’)
$warrior++;
if ($_POST[‘disciplined’] == ‘yes’)
$warrior++;
if ($_POST[‘goal_oriented’] == ‘yes’)
$warrior++;
if ($_POST[‘calculating’] == ‘yes’)
$warrior++;
if ($_POST[‘rescuer’] == ‘yes’)
$warrior++;
if ($_POST[‘generous’] == ‘yes’)
$warrior++;
if ($_POST[‘discerning’] == ‘yes’)
$warrior++;
if ($_POST[‘wise’] == ‘yes’)
$warrior++;
if ($_POST[‘financially_successful’] == ‘yes’)
$warrior++;
if ($_POST[‘competitive’] == ‘yes’)
$warrior++;
if ($_POST[‘loyal’] == ‘yes’)
$warrior++;
if ($_POST[‘cautious’] == ‘yes’)
$warrior++;

$martyr = 0;
if ($_POST[‘feels_betrayed’] == ‘yes’)
$martyr++;
if ($_POST[‘highly_critical’] == ‘yes’)
$martyr++;
if ($_POST[‘judgemental’] == ‘yes’)
$martyr++;
if ($_POST[‘rescuer’] == ‘yes’)
$martyr++;
if ($_POST[‘manipulative’] == ‘yes’)
$martyr++;
if ($_POST[‘controlling’] == ‘yes’)
$martyr++;
if ($_POST[‘long_suffering’] == ‘yes’)
$martyr++;
if ($_POST[‘caretaker’] == ‘yes’)
$martyr++;
if ($_POST[‘self_sacrificing’] == ‘yes’)
$martyr++;
if ($_POST[‘passive_aggressive’] == ‘yes’)
$martyr++;
if ($_POST[‘compassionate’] == ‘yes’)
$martyr++;
if ($_POST[‘harbors_resentment’] == ‘yes’)
$martyr++;

$fool = 0;
if ($_POST[‘financially_irrisponsible’] == ‘yes’)
$fool++;
if ($_POST[‘lives_for_today’] == ‘yes’)
$fool++;
if ($_POST[‘happy_go_lucky’] == ‘yes’)
$fool++;
if ($_POST[‘restless’] == ‘yes’)
$fool++;
if ($_POST[‘undisciplined’] == ‘yes’)
$fool++;
if ($_POST[‘impetuous’] == ‘yes’)
$fool++;
if ($_POST[‘optimistic’] == ‘yes’)
$fool++;
if ($_POST[‘overly_generous’] == ‘yes’)
$fool++;
if ($_POST[‘adventurous’] == ‘yes’)
$fool++;
if ($_POST[‘lives_for_the_future’] == ‘yes’)
$fool++;

$creator_artist = 0;
if ($_POST[‘internally_motivated’] == ‘yes’)
$creator_artist++;
if ($_POST[‘detatched’] == ‘yes’)
$creator_artist++;
if ($_POST[‘loner’] == ‘yes’)
$creator_artist++;
if ($_POST[‘seeker’] == ‘yes’)
$creator_artist++;
if ($_POST[‘tells_the_truth’] == ‘yes’)
$creator_artist++;
if ($_POST[‘non_materialistic’] == ‘yes’)
$creator_artist++;
if ($_POST[‘passive’] == ‘yes’)
$creator_artist++;
if ($_POST[‘non_confrontational’] == ‘yes’)
$creator_artist++;
if ($_POST[‘artistic’] == ‘yes’)
$creator_artist++;
if ($_POST[‘spiritual’] == ‘yes’)
$creator_artist++;

$tyrant = 0;
if ($_POST[‘unforgiving’] == ‘no’)
$tyrant++;
if ($_POST[‘calculating’] == ‘yes’)
$tyrant++;
if ($_POST[‘highly_critical’] == ‘yes’)
$tyrant++;
if ($_POST[‘aggressive’] == ‘yes’)
$tyrant++;
if ($_POST[‘manipulative’] == ‘yes’)
$tyrant++;
if ($_POST[‘controlling’] == ‘yes’)
$tyrant++;
if ($_POST[‘financially_successful’] == ‘yes’)
$tyrant++;
if ($_POST[‘fearful’] == ‘yes’)
$tyrant++;
if ($_POST[‘highly_materialistic’] == ‘yes’)
$tyrant++;
if ($_POST[‘secretive’] == ‘yes’)
$tyrant++;
if ($_POST[‘obsessive_compulsive’] == ‘yes’)
$tyrant++;
if ($_POST[‘rigid’] == ‘yes’)
$tyrant++;
if ($_POST[‘oppressive’] == ‘yes’)
$tyrant++;
if ($_POST[‘prone_to_rage_or_violence’] == ‘yes’)
$tyrant++;

$magician = 0;
if ($_POST[‘trusting’] == ‘yes’)
$magician++;
if ($_POST[‘powerful’] == ‘yes’)
$magician++;
if ($_POST[‘confident’] == ‘yes’)
$magician++;
if ($_POST[‘generous’] == ‘yes’)
$magician++;
if ($_POST[‘loving’] == ‘yes’)
$magician++;
if ($_POST[‘conscious’] == ‘yes’)
$magician++;
if ($_POST[‘open_to_flow’] == ‘yes’)
$magician++;
if ($_POST[‘compassionate’] == ‘yes’)
$magician++;
if ($_POST[‘wise’] == ‘yes’)
$magician++;
if ($_POST[‘optimistic’] == ‘yes’)
$magician++;
if ($_POST[‘lives_in_present’] == ‘yes’)
$magician++;
if ($_POST[‘detatched’] == ‘yes’)
$magician++;
if ($_POST[‘tells_the_truth’] == ‘yes’)
$magician++;
if ($_POST[‘financially_balanced’] == ‘yes’)
$magician++;
if ($_POST[‘vibrant’] == ‘yes’)
$magician++;
if ($_POST[‘transforms_reality’] == ‘yes’)
$magician++;
if ($_POST[‘spiritual’] == ‘yes’)
$magician++; }
?>[/code]

This is the submit button

[code=html]
<input type=”submit” value=”Complete” name=”calculate”>[/code]

And here’s the results code

[code=php]<?php
echo ‘<b>Innocent ‘ . $innocent . ‘</b><br><br>’;
echo ‘<b>Victim ‘ . $victim . ‘</b><br><br>’;
echo ‘<b>Warrior ‘ . $warrior . ‘</b><br><br>’;
echo ‘<b>Martyr ‘ . $martyr . ‘</b><br><br>’;
echo ‘<b>Fool ‘ . $fool . ‘</b><br><br>’;
echo ‘<b>Creator/Artist ‘ . $creator_artist . ‘</b><br><br>’;
echo ‘<b>Tyrant ‘ . $tyrant . ‘</b><br><br>’;
echo ‘<b>Magician ‘ . $magician . ‘</b><br><br>’;

?>[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@TecBratApr 17.2009 — If you make the form submit to PHP_SELF, and put your handler on that page, it will display there. The problem will be if you want your answers to be remembered. If you do, you'll need to echo the word "checked" in the input field for each checked word.[code=php]
<?php if ($_POST['anxious'] == 'yes'){$innocent++; $anxious_ck='checked'}
// do this for each word.
?>
<form method="POST" action="<?php echo $_SERVER[PHP_SELF]; ?>">
Anxious <input type="radio" name="anxious" value="yes" <?php echo $anxious_ck; ?>>
[/code]
×

Success!

Help @jessnoonyes 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.18,
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,
)...