Error redirecting based off chosen answers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thunderchld
Forum Newbie
Posts: 3
Joined: Sun Jan 04, 2009 6:28 pm

Error redirecting based off chosen answers

Post by thunderchld »

Hello, I want to start by saying I am sorry if I post this wrong.

I have searched google/php forms/etc for an answer but it seems to be each situation is diffrent and I'm not able to get it just right for me. What I am trying to do is: 1.User fills out a quiz. 2.Based off certain answers, certain responses show up. (working). I am now being asked to change it where instead of showing a final score and topics, it needs to redirect to a page dedicated to that - I have diabetes == true user is redirected to diabetic.php. Now - trick is, there are 'levels' - Diabetics > Heart Disease > Cancer > Nothing. Each has it's own question due to the scoring. I hope that helps.

I am not sure what code I need to post as I think I'll have to re-write it due to the passing of scores from the quiz page to the new page to show the score there. I've ommited the questions that I am not concerned about.

Code: Select all

 
<?php
 
$iteration = 0;
 
if ($_POST['fff_x']) {
 
/* Scoreing / point code */
 
$cat01score = $dietpoints + $hwpoints;
$cat02score = $expoints;
$cat03score = $labmedpoints;
$cat04score = $usepoints;
 
$score = $cat01score + $cat02score + $cat03score + $cat04score;
 
$iteration = 1;
 
/* This is the 'questions' results that need to re-direct */
if ($q06 != "c") {$cat05statement .= "Based off your answers, we feel you should check out the:
<br /><center><a href='http://www.foodfitnessfirst.com/DiabeticSpiral.php'><img src='images/Button_DiabeticSpiral.png' alt='Diabetic Spiral' border=0 /></a></center>";}  /* should be  sent to 'DiabeticSpiral.php' */
 
elseif ($q07 != "c") {$cat05statement .= "Based off your answers, we feel you should check out the:
<br /><center><a href='http://www.foodfitnessfirst.com/wellness/LowSodium/LSSpiral.php'><img src='images/Button_LowNASpiral.png' alt='Low Sodium Spiral' border=0 /></a></center>";}
 
elseif ($q09 != "c") {$cat05statement .= "Based off your answers, we feel you should check out the:
<br /><center><a href='http://www.foodfitnessfirst.com/RenalSpiral.php'><img src='images/Button_RenalSpiral.png' alt='Renal Spiral' border=0 /></a></center>";}
 
else {$cat05statement .= "Based off your answers, we feel you should check out the:
<br /><center><a href='http://www.foodfitnessfirst.com/spiral_well.php'><img src='images/Button_HealthySpiral.png' alt='Healthy Spiral' border=0 /></a></center>";}
 
}
?>
 
<?php
 
if ( $iteration == 1 ) { print <<<EOF
 
<html> <body>
    $totalscore
    <h4>Four Categories and the Factor for each area:</h4>
  
    <table cellpadding="5" cellspacing="0" width="100%" style="border:solid black thin;">
        <tr>
            <td valign="bottom" align="left"><p style="color:green;"><strong>Category</strong></p></td>
            <td valign="bottom" align="center"><p style="color:green;"><strong>Maximum<br />Score</strong></p></td>
            <td valign="bottom" align="center"><p style="color:green;"><strong>Your<br />Score</strong></p></td>
        </tr>
        <tr>
            <td colspan="3"><hr color="black" width="100%"></td>
        </tr>
        <tr>
            <td valign="top" align="left"><p><strong>Diet/Height/Weight</strong></p></td>
            <td valign="top" align="center"><p>30</p></td>
            <td valign="top" align="center"><p>$cat01score</p></td>
        </tr>
        <tr>
            <td colspan="3">$cat01statement</td>
        </tr>
        <tr>
            <td colspan="3"><hr color="black" width="100%"></td>
        </tr>
        <tr>
            <td valign="top" align="left"><p><strong>Exercise</strong></p></td>
            <td valign="top" align="center"><p>15</p></td>
            <td valign="top" align="center"><p>$cat02score</p></td>
        </tr>
        <tr>
            <td colspan="3">$cat02statement</td>
        </tr>
        <tr>
            <td colspan="3"><hr color="black" width="100%"></td>
        </tr>
        <tr>
            <td valign="top" align="left"><p><strong>Disease/Labs/Meds</strong></p></td>
            <td valign="top" align="center"><p>30</p></td>
            <td valign="top" align="center"><p>$cat03score</p></td>
        </tr>
        <tr>
            <td colspan="3">$cat03statement</td>
        </tr>
        <tr>
            <td colspan="3"><hr color="black" width="100%"></td>
        </tr>
        <tr>
            <td valign="top" align="left"><p><strong>Alcohol/Tobacco</strong></p></td>
            <td valign="top" align="center"><p>25</p></td>
            <td valign="top" align="center"><p>$cat04score</p></td>
        </tr>
        <tr>
            <td colspan="3">$cat04statement</td>
        </tr>
        <tr>
            <td colspan="3"><hr color="black" width="100%"></td>
        </tr>
        <tr>
            <td valign="top" align="left" colspan="3"><p><strong>Related Food Spiral</strong></p></td>
        </tr>
        <tr>
            <td colspan="3">$cat05statement</td>
        </tr>
 
    </table>
  </div>
</div>
 
</body></html>
 
EOF; }
else { print <<<END
 
<html><body>
    <h2>Favorable Fitness Factor</h2>
    <form method="post">
 
    /* These are the quesitons that should determine the redirect. */
            <h3>Health Conditions</h3>
        Do you have Diabetes?<br />
        <input type="radio" name="q06" size=2 value="a" tabindex="38" />Yes, and my doctor feels it IS under control.<br />
        <input type="radio" name="q06" size=2 value="b" />Yes, and my doctor feels it IS NOT under control.<br />
        <input type="radio" name="q06" size=2 value="c" />No<br /><br />
  
        Do you have Heart Disease (including High Blood Pressure or Stroke)?<br />
        <input type="radio" name="q07" size=2 value="a" tabindex="39" />Yes, and my doctor feels it IS under control.<br />
        <input type="radio" name="q07" size=2 value="b" />Yes, and my doctor feels it IS NOT under control.<br />
        <input type="radio" name="q07" size=2 value="c" />No<br /><br />
 
        Do you have Cancer?<br />
        <input type="radio" name="q08" size=2 value="a" tabindex="40" />Yes, and my doctor feels it IS under control.<br />
        <input type="radio" name="q08" size=2 value="b" />Yes, and my doctor feels it IS NOT under control.<br />
        <input type="radio" name="q08" size=2 value="c" />No<br /><br />
 
        Do you have  Renal Disease?<br />
        <input type="radio" name="q09" size=2 value="a" tabindex="41" />Yes, and my doctor feels it IS under control.<br />
        <input type="radio" name="q09" size=2 value="b" />Yes, and my doctor feels it IS NOT under control.<br />
        <input type="radio" name="q09" size=2 value="c" />No<br /><br />
  
        Does your family have a history of Diabetes, Heart Disease, Stroke, High Blood Pressure, Cancer, or Kidney Disease?<br />
        <input type="radio" name="q10" size=2 value="a" tabindex="42" />Yes<br />
        <input type="radio" name="q10" size=2 value="b" />No<br /><br />
 
       <div align="center">
        <strong>After answering the questions, click on the button below to get your FFF score:</strong><br /><br />
        <input type="image" src="/images/scorebutton.jpg" name="fff" value="Get My Score" size="228,56" border="0" tabindex="69" />
      </div>
    </form>
 
</body></html>
 
END; } ?>
 
If someone could suggest something similar, I'd be up for that as well. Please let me know if you need to see more of the current code I have, I'll be happy to post a link to the full code.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Error redirecting based off chosen answers

Post by requinix »

Take a look at header.

Code: Select all

header("Location: /DiabeticSpiral.php");
thunderchld
Forum Newbie
Posts: 3
Joined: Sun Jan 04, 2009 6:28 pm

Re: Error redirecting based off chosen answers

Post by thunderchld »

I cannot do the header function because I cannot have any text/code before it. And if I put it at the top of the page, it will re-direct before they even taken the quiz.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Error redirecting based off chosen answers

Post by andyhoneycutt »

You can manipulate the header at any time before you've started sending data to the output buffer. You can run all sorts of logic before you do anything with the header as long as you haven't yet pushed any data to the user's screen / output buffer.

-Andy
thunderchld
Forum Newbie
Posts: 3
Joined: Sun Jan 04, 2009 6:28 pm

Re: Error redirecting based off chosen answers

Post by thunderchld »

I've re-tried the header function:

Code: Select all

 
<?php
 
if ( $iteration == 1 ) { 
print <<<EOF
 
<?php header("Location: $cat05statement"); ?>
 
EOF;
}
else { ...
 
and I end up with

Code: Select all

 
"); ?> 
 
or I've tried:

Code: Select all

 
<?php
 
if ( $iteration == 1 ) { 
print <<<EOF
 
 header("Location: $cat05statement");
 
EOF;
}
else { ...
 

Code: Select all

 
header("Location: "); 
 
As well as I've tried posting directly to the link and I get the same results as the second output.
Post Reply