Web Analytics Made Easy -
StatCounter Values not adding up right. - CodingForum

Announcement

Collapse
No announcement yet.

Values not adding up right.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Values not adding up right.

    Wow this is so broken and I have no idea why. What I have is a form with multiple checkboxes, each with their own ID. For each box that's checked, a value of 1 is supposed to be added to one of eight...variables? I'm sorry I don't know the exact word. However even if I check nothing and submit the form all eight have values and I can't figure out what I did wrong.

    Here's the form. You can click on names to select them, submit to see the broken results.

    I'm still a noob with PHP so I'm sure I did something wrong. Any advice would be awesome!

    Here's the php:
    PHP Code:
    <?php
    $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++;
    ?>
    <?php
    $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++;
    ?>
    <?php
    $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++;
    ?>
    <?php
    $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++;
    ?>
    <?php
    $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++;
    ?>
    <?php
    $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++;
    ?>
    <?php
    $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++;
    ?>
    <?php
    $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++;
    ?>
    <html>
    <head>
    <title>Your Results</title>
    </head>
    <body>
    <h1>Your Results</h1>

    <?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>';


    ?>

    </body>
    </html>
    Last edited by JohnDubya; Apr 28, 2009, 11:36 AM. Reason: remove url, as requested

  • #2
    I've just checked the page and it looks to be working. Can this be closed?

    Comment


    • #3
      No it's not working. If you don't click anything at all and press "complete" you'll be taken to the results page. Since nothing was clicked everything should be zero, but they're not.

      Comment


      • #4
        hmm when i press complete with nothing selected it shows everything as zero
        Click image for larger version

Name:	Screenshot.jpg
Views:	1
Size:	39.9 KB
ID:	2265081 i attached an screenshot of it ..

        Comment


        • #5
          What in the world.....hm. When I press it in the browser that I've been testing it in (firefox) I get values even after I clear my cache and cookies. But when i opened it in Opera for the first time and submitted it the values were zero. You're right. Why won't the value clear out?

          Comment


          • #6
            Yes, if you pick items, submit, then go back and refresh to clear items, then submit again, you get the same result page (with item counts.) You need to set a header on the result page that tells the browser (edit: and any other caches along the way - your web server could be caching it) to not use a cached page for the result page.
            Last edited by CFMaBiSmAd; Apr 16, 2009, 11:03 AM.
            Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

            Comment


            • #7
              Do I use this to do that:
              <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

              Actually I was going to ask if I could print the results on the same page. Put that large bit of PHP up at the top of the page, the results area below, and have the "complete" button just refresh, or fill in, the results area.

              Comment


              • #8
                could print the results on the same page
                You can do just about anything you want in programming.

                Give your submit button a name="some name of your choice here" parameter so that you can test it to see if the form has been submitted -

                if(isset($_POST['some name of your choice here'])){
                // form processing code here
                }
                Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

                Comment


                • #9
                  Thanks!

                  I'm sorry I'm such a noob. At the very top of my file do I put this? I'm guessing not because that makes it mad. Maybe I ended it wrong.

                  PHP Code:
                  <?php if(isset($_POST['results'])) {
                  <?
                  php
                  $innocent 
                  0;
                  if (
                  $_POST['anxious'] == 'yes')
                  $innocent++;

                  ....
                  yada yada 

                  if ($_POST['spiritual'] == 'yes')
                  $magician++;
                  ?>
                      }  ?>

                  Comment


                  • #10
                    Hm. Ok I removed all of the <?php ?>'s inside and that got rid of the error, although I'm not sure if that was what I was supposed to do. I changed the submit button name to "calculate" and also put that into the if(isset($_POST['calculate'])) . And I moved the results php to be under the "complete" button. But it doesn't really do anything.

                    Here are snippets of what I have:
                    At the top-
                    PHP Code:
                    <?php if(isset($_POST['calculate'])){

                    $innocent 0;
                    if (
                    $_POST['anxious'] == 'yes') .....

                    ...if (
                    $_POST['spiritual'] == 'yes')
                    $magician++; 
                    }
                    ?>

                    The submit button:
                    Code:
                    <input type="submit" value="Complete" name="calculate">

                    The results area:
                    PHP Code:
                    <h1>Your Results</h1>

                    <?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>';


                    ?>

                    Comment

                    Working...
                    X