Results 1 to 4 of 4

Thread: PHP Programming question regarding if statements?

  1. #1
    closebys is offline Unknown Net Builder
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Programming question regarding if statements?

    Hi Friends,

    This is the code of my current PHP project:

    mainpage.php :
    HTML Code:
    <div><h1> Survey Questionnaire</h1></div>
    
    <form id="form1" name="form1" method="post" action="process.php">
    <label>Name:
    </label>
    <input type="text" name="name" id="name" />
    </label>
    
    <label> 
    
    Age:
    <input type="text" name="age" id="age" />
    
    Be prepared to answer some difficult questions!
    
    How do you feel? </label>
    <p>
    <label>
    <input type="radio" name="emotion" value="happy" id="happy" />
    happy </label>
    
    <label>
    <input type="radio" name="emotion" value="sad" id="sad " />
    sad
    
    </label>
    <label>
    <input type="radio" name="emotion" value="angry" id="angry " />
    angry
    
    Why are you doing this survey?
    
    <input type="radio" name="reason" value="there is nothing better to do" id="nothing" /> 
    there's nothing better to do</label>
    
    <label>
    <input type="radio" name="reason" value="you have no life" id="life" /> 
    you have no life</label>
    
    
    <label>
    <input type="radio" name="reason" value="you are being held against your will in an abandoned shack forced to answer these questions." id="held" /> 
    you are being held against your will in an abandoned shack forced to answer these questions.</label>
    </p>
    <p>What is your favorite color?</p>
    <p>
    <label>
    <input type="radio" name="color" value="red" id="red" />
    red</label>
    
    
    <label>
    <input type="radio" name="color" value="yellow" id="yellow" />
    yellow</label>
    
    <label>
    <input type="radio" name="color" value="green" id="green" />
    green</label>
    
    
    <label>
    <input type="radio" name="color" value="blue" id="blue" />
    blue</label>
    
    <label>
    <input type="radio" name="color" value="orange" id="orange" />
    orange</label>
    
    </p>
    <p>
    <label>What is your favorite season?
    
    <input type="radio" name="season" value="autumn" id="autumn" />
    autumn </label>
    
    <label>
    <input type="radio" name="season" value="spring" id="spring" /> 
    spring</label>
    
    <label>
    <input type="radio" name="season" value="summer" id="summer" /> 
    summer</label>
    
    <label>
    <input type="radio" name="season" value="winter" id="winter" /> 
    winter</label>
    
    <label>
    
    What is your favorite genre of music?
    
    <input type="radio" name="music" value="rock" id="rock" /> 
    rock
    </label>
    
    <label>
    <input type="radio" name="music" value="hip-hop" id="hip-hop" />
    hip-hop </label>
    
    <label>
    <input type="radio" name="music" value="dance" id="dance" /> 
    dance
    </label>
    
    <label>
    <input type="radio" name="music" value="pop" id="pop" /> 
    pop
    </label>
    
    <label>
    <input type="radio" name="music" value="alternative" id="alternative" /> 
    alternative
    </label>
    
    <label>
    
    <input type="submit" name="button_1" id="button_1" value="Submit" />
    </label>
    
    </p>
    </form>
    process.php:
    PHP Code:
    <?php

    $name 
    $_POST['name']; 
    $age $_POST['age'];
    $emotion $_POST['emotion'];
    $reason $_POST['reason'];
    $color $_POST['color'];
    $season $_POST['season'];
    $music $_POST['music'];
    echo 
    "<p>" $name ", you are " $age " years old." "</p>";
    echo 
    "And you are " $emotion;
    echo 
    "<p>" $name ", you are completing this survey because " $reason "</p>";
    echo 
    "Your favorite color is " $color;
    echo 
    "<p>" $name ", your favorite season is " $season "</p>";
    echo 
    "You like " $music " music.";

    ?>


    What would the if statement be if I wanted $color to change based upon the color? i.e if someone picked yellow as their favorite color how would I make the echoed $color text yellow?
    Last edited by Mr.Bill; 30 April, 2010 at 17:51 PM.

  2. #2
    DickTracy is offline Newbie Net Builder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    12
    Thanked 19 Times in 12 Posts
    I don't have time to test it at the moment but perhaps something like changing
    echo "Your favorite color is " . $color;
    to
    echo '<p style="color:'.$color.'" >
    Your favorite color is '. $color.'</p>';

    I've not tried with 'real' color names rather than hex numbers but think it works...

  3. #3
    small is offline Newbie Net Builder
    Join Date
    Apr 2009
    Posts
    35
    Thanks
    7
    Thanked 10 Times in 9 Posts
    change this line
    Code:
     echo "Your favorite color is " . $color;


    to
    Code:
    echo "Your favorite color is <span style='color: $color;'>" . $color . "</span>";

  4. #4
    dreamstone is offline Unknown Net Builder
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    echo "<span style=\"color:" . $color . "\">Your favorite color is " . $color . "</span>";

Similar Threads

  1. What programming...
    By Coelho in forum Community Building
    Replies: 6
    Last Post: 30 June, 2010, 21:42 PM
  2. Programming
    By Sbfc_ in forum Monetizing
    Replies: 3
    Last Post: 7 June, 2010, 10:18 AM
  3. Testing SQL Statements
    By chatterbox in forum Databases
    Replies: 3
    Last Post: 29 August, 2009, 10:05 AM
  4. Jokes and funny statements
    By mega in forum General Chat
    Replies: 5
    Last Post: 16 May, 2009, 14:47 PM

Tags for this Thread

Bookmarks

Posting Permissions

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