Jump to content

Recommended Posts

<?php

   function DisplayQuizResults()
   {
      // Determine That The User Has Come To This Page From
      // A Proper Quiz Page
      if( !isset( $_POST[ 'submit' ] ) )
      {
         // Invalid Access
         die( "Sorry, direct access to this file is not permitted.\n" );
      }

      // Obtain Username
      if( isset( $_POST[ 'name' ] ) && $_POST[ 'name' ] != "" )
      {
         $name = $_POST[ 'name' ];
      }
      else
      {
         die( "You forgot to fill in your name.\n" );
      }

      // Obtain Quiz Answers
      $q = array();
      for( $x = 1; $x<20; $x++ )
      {
         if( isset( $_POST[ 'Q'.$x ] ) )
         {
            $q[$x] = $_POST[ 'Q'.$x ];
         }
         else
         {
            die( "You forgot to fill in answer: ". $x . "\n" );
         }
      }

      // Display Results
      echo( "<p>Hello: " . $name . "<br><br><br>\n" );
   	if( ($q[$x=1] + $q[$x]<21) >= 0 && ($q[$x=1] + $q[$x]<21) <= 20 );
      {
  echo ('im a little teapot'."<br><br><br><br><br>");

   	}  
   	if( ($q[$x=1] + $q[$x]<21) >= 21 && ($q[$x=1] + $q[$x]<21) <= 40 );
      {
  echo ('im a medium teapot'."<br><br><br><br><br>");

   	} 
   	if( ($q[$x=1] + $q[$x]<21) >= 41 && ($q[$x=1] + $q[$x]<21) <= 60 );
      {
  echo ('im a large teapot'."<br><br><br><br><br>");

   	} 
   	if( ($q[$x=1] + $q[$x]<21) >= 61 && ($q[$x=1] + $q[$x]<21) <= 80 );
      {
  echo ('im a fat teapot'."<br><br><br><br><br>");

   	} 
   	if( ($q[$x=1] + $q[$x]<21) >= 81 && ($q[$x=1] + $q[$x]<21) <= 100 );
      {
  echo ('im a jenny craig teapot'."<br><br><br><br>");
  
  
  }
   }

?>

<HTML>
<HEAD>
  <TITLE> Quiz Results </TITLE>
</HEAD>
<BODY>

<? DisplayQuizResults(); ?>

</BODY>
</HTML>

 

it isnt working correctly for some reason. no matter what i answer it spits out all outcomes.

here is the quiz code i think it is irrelevant though.

 

<?php
$qid = "Quiz ID-00";
?>
<html>
<head>
<title><? echo "NLP VIDEO $qid"; ?></title>
        <style type="text/css">
            .style2
            {
                width: 275px;
            }
            .style3
            {
                width: 485px;
            }
            .style8
            {
                width: 176px;
            }
        </style>
</head>
<body>
    <h3><? echo "nlp video $qid"; ?></h3>
<form action="results.php" method="post">
<p>
        Rate on a Scale of 1-5 how each of these questions make you feel.</p>
<p>
        Your Name: <input type="text" name="name"></p>
    <table cellpadding="0" cellspacing="0" class="style3">
        <tr>
            <td class="style8">
                Questions or little tidbit of words here</td>
            <td>
                1          2       
                3        4       
                5 
            </td>
        </tr>
        <tr>
            <td class="style8">
                Question</td>
            <td>
                <input id="01" name="Q1" type="radio" value="1" />    
                <input id="02" name="Q1" type="radio" value="2" />    
                <input id="03" name="Q1" type="radio" value="3" />    
                <input id="04" name="Q1" type="radio" value="4" />    
                <input id="05" name="Q1" type="radio" value="5" />    
</td>
        </tr>
    </table>
    <table cellpadding="0" cellspacing="0" class="style3">
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="1" name="Q2" type="radio" value="1" />    
                <input id="2" name="Q2" type="radio" value="2" />    
                <input id="3" name="Q2" type="radio" value="3" />    
                <input id="4" name="Q2" type="radio" value="4" />    
                <input id="5" name="Q2" type="radio" value="5" />    
</td>
</tr>
        <tr>
            <td class="style8">
                Question</td>
            <td>
                <input id="6" name="Q3" type="radio" value="1" />    
                <input id="7" name="Q3" type="radio" value="2" />    
                <input id="8" name="Q3" type="radio" value="3" />    
                <input id="9" name="Q3" type="radio" value="4" />    
                <input id="10" name="Q3" type="radio" value="5" />    
</td>
        </tr>
    </table>
    <table cellpadding="0" cellspacing="0" class="style3">
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="Radio11" name="Q4" type="radio" value="1" />    
                <input id="Radio12" name="Q4" type="radio" value="2" />    
                <input id="Radio13" name="Q4" type="radio" value="3" />    
                <input id="Radio14" name="Q4" type="radio" value="4" />    
                <input id="Radio15" name="Q4" type="radio" value="5" />    
</td>        </tr>
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="Radio16" name="Q5" type="radio" value="1" />    
                <input id="Radio17" name="Q5" type="radio" value="2" />    
                <input id="Radio18" name="Q5" type="radio" value="3" />    
                <input id="Radio19" name="Q5" type="radio" value="4" />    
                <input id="Radio20" name="Q5" type="radio" value="5" />    
</td>
</tr>
        <tr>
            <td class="style8">
                Question</td>
            <td>
                <input id="Radio21" name="Q6" type="radio" value="1" />    
                <input id="Radio22" name="Q6" type="radio" value="2" />    
                <input id="Radio23" name="Q6" type="radio" value="3" />    
                <input id="Radio24" name="Q6" type="radio" value="4" />    
                <input id="Radio25" name="Q6" type="radio" value="5" />    
</td>
        </tr>
    </table>
    <table cellpadding="0" cellspacing="0" class="style3">
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="Radio26" name="Q7" type="radio" value="1" />    
                <input id="Radio27" name="Q7" type="radio" value="2" />    
                <input id="Radio28" name="Q7" type="radio" value="3" />    
                <input id="Radio29" name="Q7" type="radio" value="4" />    
                <input id="Radio30" name="Q7" type="radio" value="5" />    
</td>        </tr>
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="Radio31" name="Q8" type="radio" value="1" />    
                <input id="Radio32" name="Q8" type="radio" value="2" />    
                <input id="Radio33" name="Q8" type="radio" value="3" />    
                <input id="Radio34" name="Q8" type="radio" value="4" />    
                <input id="Radio35" name="Q8" type="radio" value="5" />    
</td>
</tr>
        <tr>
            <td class="style8">
                Question</td>
            <td>
                <input id="Radio36" name="Q9" type="radio" value="1" />    
                <input id="Radio37" name="Q9" type="radio" value="2" />    
                <input id="Radio38" name="Q9" type="radio" value="3" />    
                <input id="Radio39" name="Q9" type="radio" value="4" />    
                <input id="Radio40" name="Q9" type="radio" value="5" />    
</td>
        </tr>
    </table>
    <table cellpadding="0" cellspacing="0" class="style3">
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="Radio41" name="Q10" type="radio" value="1" />    
                <input id="Radio42" name="Q10" type="radio" value="2" />    
                <input id="Radio43" name="Q10" type="radio" value="3" />    
                <input id="Radio44" name="Q10" type="radio" value="4" />    
                <input id="Radio45" name="Q10" type="radio" value="5" />    
</td>        </tr>
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="Radio46" name="Q11" type="radio" value="1" />    
                <input id="Radio47" name="Q11" type="radio" value="2" />    
                <input id="Radio48" name="Q11" type="radio" value="3" />    
                <input id="Radio49" name="Q11" type="radio" value="4" />    
                <input id="Radio50" name="Q11" type="radio" value="5" />    
</td>
</tr>
        <tr>
            <td class="style8">
                Question</td>
            <td>
                <input id="Radio51" name="Q12" type="radio" value="1" />    
                <input id="Radio52" name="Q12" type="radio" value="2" />    
                <input id="Radio53" name="Q12" type="radio" value="3" />    
                <input id="Radio54" name="Q12" type="radio" value="4" />    
                <input id="Radio55" name="Q12" type="radio" value="5" />    
</td>
        </tr>
    </table>
    <table cellpadding="0" cellspacing="0" class="style3">
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="Radio56" name="Q13" type="radio" value="1" />    
                <input id="Radio57" name="Q13" type="radio" value="2" />    
                <input id="Radio58" name="Q13" type="radio" value="3" />    
                <input id="Radio59" name="Q13" type="radio" value="4" />    
                <input id="Radio60" name="Q13" type="radio" value="5" />    
</td>        </tr>
        <tr>
            <td class="style8">
                Question</td>
             <td>
                <input id="Radio61" name="Q14" type="radio" value="1" />    
                <input id="Radio62" name="Q14" type="radio" value="2" />    
                <input id="Radio63" name="Q14" type="radio" value="3" />    
                <input id="Radio64" name="Q14" type="radio" value="4" />    
                <input id="Radio65" name="Q14" type="radio" value="5" />    
</td>
</tr>
        <tr>
            <td class="style8">
                Question</td>
            <td>
                <input id="Radio66" name="Q15" type="radio" value="1" />    
                <input id="Radio67" name="Q15" type="radio" value="2" />    
                <input id="Radio68" name="Q15" type="radio" value="3" />    
                <input id="Radio69" name="Q15" type="radio" value="4" />    
                <input id="Radio70" name="Q15" type="radio" value="5" />    
</td>
        </tr>
    </table>
    <table cellpadding="0" cellspacing="0" class="style3">
        <tr>
            <td class="style8">
                Question</td>
             <td class="style2">
                <input id="Radio71" name="Q16" type="radio" value="1" />    
                <input id="Radio72" name="Q16" type="radio" value="2" />    
                <input id="Radio73" name="Q16" type="radio" value="3" />    
                <input id="Radio74" name="Q16" type="radio" value="4" />    
                <input id="Radio75" name="Q16" type="radio" value="5" />    
</td>        </tr>
        <tr>
            <td class="style8">
                Question</td>
                             <td class="style2">
                <input id="Radio76" name="Q17" type="radio" value="1" />    
                <input id="Radio77" name="Q17" type="radio" value="2" />    
                <input id="Radio78" name="Q17" type="radio" value="3" />    
                <input id="Radio79" name="Q17" type="radio" value="4" />    
                <input id="Radio80" name="Q17" type="radio" value="5" />    
</td>
            <td>
                 </td>
        </tr>
                </tr>
        <tr>
            <td class="style8">
                Question</td>
                             <td class="style2">
                <input id="Radio81" name="Q18" type="radio" value="1" />    
                <input id="Radio82" name="Q18" type="radio" value="2" />    
                <input id="Radio83" name="Q18" type="radio" value="3" />    
                <input id="Radio84" name="Q18" type="radio" value="4" />    
                <input id="Radio85" name="Q18" type="radio" value="5" />    
</td>
            <td>
                 </td>
        </tr>
                </tr>
        <tr>
            <td class="style8">
                Question</td>
                             <td class="style2">
                <input id="Radio86" name="Q19" type="radio" value="1" />    
                <input id="Radio87" name="Q19" type="radio" value="2" />    
                <input id="Radio88" name="Q19" type="radio" value="3" />    
                <input id="Radio89" name="Q19" type="radio" value="4" />    
                <input id="Radio90" name="Q19" type="radio" value="5" />    
</td>
            <td>
                 </td>
        </tr>
                </tr>
        <tr>
            <td class="style8">
                Question</td>
                             <td class="style2">
                <input id="Radio91" name="Q20" type="radio" value="1" />    
                <input id="Radio92" name="Q20" type="radio" value="2" />    
                <input id="Radio93" name="Q20" type="radio" value="3" />    
                <input id="Radio94" name="Q20" type="radio" value="4" />    
                <input id="Radio95" name="Q20" type="radio" value="5" />    
</td>
            <td>
                 </td>
        </tr>

    </table>
<p><input type="submit" name="submit" value="Submit Quiz"></p>
<input type="hidden" name="qp" value="quiz00.php">
</form>
</body>
</html>

 

any help will be appreciated

 

Link to comment
https://forums.phpfreaks.com/topic/107274-spitting-out-all-the-answers/
Share on other sites

tryfcode]<?php

   function DisplayQuizResults()
   {
      // Determine That The User Has Come To This Page From
      // A Proper Quiz Page
      if( !isset( $_POST[ 'submit' ] ) )
      {
         // Invalid Access
         die( "Sorry, direct access to this file is not permitted.\n" );
      }

      // Obtain Username
      if( isset( $_POST[ 'name' ] ) && $_POST[ 'name' ] != "" )
      {
         $name = $_POST[ 'name' ];
      }
      else
      {
         die( "You forgot to fill in your name.\n" );
      }

      // Obtain Quiz Answers
      $q = array();
      $total = 0;
      for( $x = 1; $x<20; $x++ )
      {
         if( isset( $_POST[ 'Q'.$x ] ) )
         {
            $q[$x] = $_POST[ 'Q'.$x ];
            $total += $q[$x];
         }
         else
         {
            die( "You forgot to fill in answer: ". $x . "\n" );
         }
      }

      // Display Results
      echo( "<p>Hello: " . $name . "<br><br><br>\n" );
   	if( $total < 21)     
   	{
  echo ('im a little teapot'."<br><br><br><br><br>");

   	}   
   	else if($total < 41)
   	{
  echo ('im a medium teapot'."<br><br><br><br><br>");
} 
   	else if($total < 61)
   	{
  echo ('im a large teapot'."<br><br><br><br><br>");

   	} 
   	else if($total <= 80 )
   	{
  echo ('im a fat teapot'."<br><br><br><br><br>");

   	} 
   	else 
   	{
  echo ('im a jenny craig teapot'."<br><br><br><br>");
  
  
}
   }

?>

<HTML>
<HEAD>
  <TITLE> Quiz Results </TITLE>
</HEAD>
<BODY>

<? DisplayQuizResults(); ?>

</BODY>
</HTML>

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.