...

View Full Version : New coder looking for help



phazlee
12-18-2008, 06:00 PM
Hi,

am doing a simple survey script. Manage to piece it together from different codes. Missing the ending part.

What I want to do is get the result part to show on a new page. How can I acheive this? The things I want to appear on a new page are in blue.

Any help is appreciated thanks.

The code :


<?php
if(isset($_POST[submit]))
{
if($_POST['que1']=="")
$strError .= "<li>Please select an answer for question 1</li>";


if($_POST['que2']=="")
$strError .= "<li>Please select an answer for question 2</li>";

if($_POST['que3']=="")
$strError .= "<li>Please select an answer for question 3</li>";


if($_POST['que4']=="")
$strError .= "<li>Please select an answer for question 4</li>";


if($_POST['que5']=="")
$strError .= "<li>Please select an answer for question 5</li>";


if($_POST['que6']=="")
$strError .= "<li>Please select an answer for question 6</li>";

if($_POST['que7']=="")
$strError .= "<li>Please select an answer for question 7</li>";


if(empty($strError)){
$Total = $_POST[que1]+$_POST[que2]+$_POST[que3]+$_POST[que4]+$_POST[que5]+$_POST[que6]+$_POST[que7];
}

}

?>
<style type="text/css">
<!--
.style2 {
font-size: 24px;
font-weight: bold;
}
-->
</style>

<form action="" method="post">
<table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3">1. Are you unable to maintain a balanced nutrition due to personal circumstances such as lack of time, laziness and lack of knowledge?</td>
</tr>
<tr>
<td width="63">Yes
<input type="radio" name="que1" value="1" <?php if($_POST[que1]==1){?> checked<?php } ?>></td>
<td width="95">Maybe
<input type="radio" name="que1" value="2" <?php if($_POST[que1]==2){?> checked<?php } ?>></td>
<td width="242">No
<input type="radio" name="que1" value="3" <?php if($_POST[que1]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">2. Are you eating too little fruits, vegetables and salads? </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que2" value="1"<?php if($_POST[que2]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que2" value="2"<?php if($_POST[que2]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que2" value="3"<?php if($_POST[que2]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">3. Are you eating too much meat and too many fatty foods? </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que3" value="1"<?php if($_POST[que3]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que3" value="2"<?php if($_POST[que3]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que3" value="3"<?php if($_POST[que3]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">4. Are you drinking too much alcohol, coffee and sweet drinks?<br>
(Alcohol does not only promote the excretion of vitamins and minerals, it also increases the need of them) </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que4" value="1"<?php if($_POST[que4]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que4" value="2"<?php if($_POST[que4]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que4" value="3"<?php if($_POST[que4]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">5. Are you eating too many sweets and simple sugars instead of wholemeal products?<br>
(Refined and denaturalized foods such as cakes, white flour, white rice)</td>
</tr>
<tr>
<td>Yes <input type="radio" name="que5" value="1"<?php if($_POST[que5]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que5" value="2"<?php if($_POST[que5]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que5" value="3"<?php if($_POST[que5]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">6. Are you eating an imbalanced diet, too quickly and too late at night? </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que6" value="1"<?php if($_POST[que6]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que6" value="2"<?php if($_POST[que6]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que6" value="3"<?php if($_POST[que6]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">7.Are you placing excessive demands on your digestive tracts and they can no longer fully digest your foods? </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que7" value="1"<?php if($_POST[que7]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que7" value="2"<?php if($_POST[que7]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que7" value="3"<?php if($_POST[que7]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3" align="center"><?=$strError;?></td>
</tr>
<tr>
<td colspan="3" align="center">&nbsp;</td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
<?php if(!empty($Total))
{ ?>

<tr>
<td colspan="3" align="center"><p>&nbsp;</p>
<p><span class="style2">Your score is
<?=$Total?>
out of 21</span></p>
<p>
<img src="images/bar.png" width="549" height="79" /><br>
</p>
<p>I recommend the following book and I hope it can improve your nutritional status.<br>
<em><b>“What Your Doctor Doesn’t Know about Nutritional Medicine May Be Killing You”</b></em> <br>
by Dr Ray Strand, M.D. </p>
<p><br>
<a href="what.htm" target="_blank"><img src="images/next1.gif" /></a> </p></td>
</tr><?php } ?>
<tr>

<td colspan="3" align="center">&nbsp;</td>
</tr>
</table></form>

Sorry bout the earlier missing PHP quotes now can someone help? Thanks

TheTVStop
12-18-2008, 06:04 PM
You would first need to store the data that you want displayed in a database.

here is a brief tutorial on how to get started with using php and mysql:

http://www.w3schools.com/PHP/php_mysql_intro.asp

Fumigator
12-18-2008, 09:03 PM
For something simple, you don't need to use a database. It looks like you just want to display a block of html after the form is submitted. For this, you should put this block of html inside your if(isset($_POST[submit])) block at the top.

Oh and also, read this link:

http://codingforums.com/showthread.php?t=68462

phazlee
12-19-2008, 07:42 AM
For something simple, you don't need to use a database. It looks like you just want to display a block of html after the form is submitted. For this, you should put this block of html inside your if(isset($_POST[submit])) block at the top.

Oh and also, read this link:

http://codingforums.com/showthread.php?t=68462

Hi

Fumigator, did you send me to the wrong post? This post is more of how to post on BB.

FWDrew
12-19-2008, 08:18 AM
Hi

Fumigator, did you send me to the wrong post? This post is more of how to post on BB.

You didnt wrap your code in php tags, hence the link telling you to wrap your code in php tags ;)

Drew

phazlee
12-19-2008, 09:28 AM
You didnt wrap your code in php tags, hence the link telling you to wrap your code in php tags ;)

Drew

Hi,

I know that already but at least also point me somewhere in the right direction :D. If not at least around the area Lol.

Fumigator
12-19-2008, 10:10 AM
I told you exactly what you should do.

phazlee
12-19-2008, 11:43 AM
I told you exactly what you should do.

Hi Fumigator, don't really understand can give me an example? Thanks.

FWDrew
12-19-2008, 12:11 PM
Hi,

I know that already but at least also point me somewhere in the right direction :D. If not at least around the area Lol.

I did, you now know how to properly post php code.


It looks like you just want to display a block of html after the form is submitted. For this, you should put this block of html inside your
if(isset($_POST[submit])) block at the top.

phazlee
12-19-2008, 03:17 PM
Hi,

manage to get it to open a new page but I cannot pass the variable $Total over to the result.php page.

Below is the code for survey.php


<?php
if(isset($_POST[submit]))
{
if($_POST['que1']=="")
$strError .= "<li>Please select an answer for question 1</li>";


if($_POST['que2']=="")
$strError .= "<li>Please select an answer for question 2</li>";

if($_POST['que3']=="")
$strError .= "<li>Please select an answer for question 3</li>";


if($_POST['que4']=="")
$strError .= "<li>Please select an answer for question 4</li>";


if($_POST['que5']=="")
$strError .= "<li>Please select an answer for question 5</li>";


if($_POST['que6']=="")
$strError .= "<li>Please select an answer for question 6</li>";

if($_POST['que7']=="")
$strError .= "<li>Please select an answer for question 7</li>";


if(empty($strError)){
$Total = $_POST[que1]+$_POST[que2]+$_POST[que3]+$_POST[que4]+$_POST[que5]+$_POST[que6]+$_POST[que7];
$arr = array("$Total", "21");

?>
<SCRIPT LANGUAGE="JAVASCRIPT">
window.location="result.php";
</SCRIPT>
<?php


}

}

?>
<style type="text/css">
<!--
.style2 {
font-size: 24px;
font-weight: bold;
}
-->
</style>

<form action="" method="post">
<table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3">1. Are you unable to maintain a balanced nutrition due to personal circumstances such as lack of time, laziness and lack of knowledge?</td>
</tr>
<tr>
<td width="63">Yes
<input type="radio" name="que1" value="1" <?php if($_POST[que1]==1){?> checked<?php } ?>></td>
<td width="95">Maybe
<input type="radio" name="que1" value="2" <?php if($_POST[que1]==2){?> checked<?php } ?>></td>
<td width="242">No
<input type="radio" name="que1" value="3" <?php if($_POST[que1]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">2. Are you eating too little fruits, vegetables and salads? </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que2" value="1"<?php if($_POST[que2]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que2" value="2"<?php if($_POST[que2]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que2" value="3"<?php if($_POST[que2]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">3. Are you eating too much meat and too many fatty foods? </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que3" value="1"<?php if($_POST[que3]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que3" value="2"<?php if($_POST[que3]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que3" value="3"<?php if($_POST[que3]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">4. Are you drinking too much alcohol, coffee and sweet drinks?<br>
(Alcohol does not only promote the excretion of vitamins and minerals, it also increases the need of them) </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que4" value="1"<?php if($_POST[que4]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que4" value="2"<?php if($_POST[que4]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que4" value="3"<?php if($_POST[que4]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">5. Are you eating too many sweets and simple sugars instead of wholemeal products?<br>
(Refined and denaturalized foods such as cakes, white flour, white rice)</td>
</tr>
<tr>
<td>Yes <input type="radio" name="que5" value="1"<?php if($_POST[que5]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que5" value="2"<?php if($_POST[que5]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que5" value="3"<?php if($_POST[que5]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">6. Are you eating an imbalanced diet, too quickly and too late at night? </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que6" value="1"<?php if($_POST[que6]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que6" value="2"<?php if($_POST[que6]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que6" value="3"<?php if($_POST[que6]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">7.Are you placing excessive demands on your digestive tracts and they can no longer fully digest your foods? </td>
</tr>
<tr>
<td>Yes <input type="radio" name="que7" value="1"<?php if($_POST[que7]==1){?> checked<?php } ?>></td>
<td>Maybe <input type="radio" name="que7" value="2"<?php if($_POST[que7]==2){?> checked<?php } ?>></td>
<td>No <input type="radio" name="que7" value="3"<?php if($_POST[que7]==3){?> checked<?php } ?>></td>
</tr>
<tr>
<td colspan="3" align="center"><?=$strError;?></td>
</tr>
<tr>
<td colspan="3" align="center">&nbsp;</td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
<?php if(!empty($Total))
{ ?><tr>
<td colspan="3" align="center"><p>&nbsp;</p>
<p><span class="style2">Your score is
<?=$Total?>
out of 21</span></p>
<p>
<img src="images/bar.png" width="549" height="79" /><br>
</p>
<p>I recommend the following book and I hope it can improve your nutritional status.<br>
<em><b>“What Your Doctor Doesn’t Know about Nutritional Medicine May Be Killing You”</b></em> <br>
by Dr Ray Strand, M.D. </p>
<p><br>
<a href="what.htm" target="_blank"><img src="images/next1.gif" /></a> </p></td>
</tr><?php } ?>
<tr>

<td colspan="3" align="center">&nbsp;</td>
</tr>
</table>
</form>

Below is the code for result.php




<tr>
<td colspan="3" align="center"><p>&nbsp;</p>
<p><span class="style2">Your score is
<?php
echo $arr[0];
echo $Total;
?>
out of 21</span></p>
<p>
<img src="images/bar.png" width="549" height="79" /><br>
</p>
<p>I recommend the following book and I hope it can improve your nutritional status.</p>
<p><br>
<b>“<em>What Your Doctor Doesnt Know about Nutritional Medicine May Be Killing You</em>”</b> <br>
by Dr Ray Strand, M.D. </p>
<p><br>
<a href="what.htm" target="_blank"><img src="images/next1.gif" /></a> </p></td>
</tr>
<tr>

<td colspan="3" align="center">&nbsp;</td>
</tr>
</table>

Can any of you guys help me on this, I need to pass the variable $Total to the result.php page

tosbourn
12-19-2008, 05:01 PM
Change


<SCRIPT LANGUAGE="JAVASCRIPT">
window.location="result.php";
</SCRIPT>

To


<SCRIPT LANGUAGE="JAVASCRIPT">
window.location="result.php?t=<?=$Total ?>";
</SCRIPT>

Then change


echo $Total;

To


echo $_GET['t'];



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum