www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Calculate results on same page?

  1. #1
    Join Date
    Feb 2007
    Posts
    108

    resolved [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. Demo

    However I'd like the results to be shown on the same page. I've been trying to set that up on this page. 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:

    PHP Code:
    <?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++; }
    ?>

    This is the submit button
    HTML Code:
    <input type="submit" value="Complete" name="calculate">

    And here's the results code
    PHP Code:
    <?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>';


    ?>

  2. #2
    Join Date
    Oct 2007
    Posts
    371
    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.
    PHP Code:
    <?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?>>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles