Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New coder looking for help

    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 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))
    ?>

    <[COLOR="Navy"]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>[/COLOR]</form>
    Sorry bout the earlier missing PHP quotes now can someone help? Thanks
    Last edited by phazlee; 12-19-2008 at 08:29 AM. Reason: Missing PHP quotes

  • #2
    New Coder
    Join Date
    Dec 2008
    Posts
    27
    Thanks
    3
    Thanked 1 Time in 1 Post
    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

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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:

    Please wrap PHP codes using the [PHP][/PHP] tag

  • #4
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    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:

    Please wrap PHP codes using the [PHP][/PHP] tag
    Hi

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

  • #5
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts
    Quote Originally Posted by phazlee View Post
    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
    Dev-Tips.com || Employee at the Envato Network || My Portfolio

  • #6
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FWDrew View Post
    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 . If not at least around the area Lol.

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I told you exactly what you should do.

  • #8
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    I told you exactly what you should do.
    Hi Fumigator, don't really understand can give me an example? Thanks.

  • #9
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts
    Quote Originally Posted by phazlee View Post
    Hi,

    I know that already but at least also point me somewhere in the right direction . 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
    PHP Code:
    if(isset($_POST[submit])) 
    block at the top.
    Dev-Tips.com || Employee at the Envato Network || My Portfolio

  • #10
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 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];
            
    $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



    PHP Code:
    <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

  • #11
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Change

    PHP Code:
     <SCRIPT LANGUAGE="JAVASCRIPT">
                        
    window.location="result.php";
                    
    </SCRIPT> 
    To

    PHP Code:
     <SCRIPT LANGUAGE="JAVASCRIPT">
                        window.location="result.php?t=<?=$Total ?>";
                    </SCRIPT>
    Then change

    PHP Code:
      echo $Total
    To
    PHP Code:
      echo $_GET['t']; 


  •  

    Posting Permissions

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