Results 1 to 2 of 2

Thread: PHP Programming question regarding if statements?

  1. #1
    New to vBFAQ
    Join Date
    Dec 2009
    Posts
    1

    PHP Programming question regarding if statements?

    Hi Friends,

    This is the code of my current PHP project:

    mainpage.php :

    <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

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

  2. #2
    New to vBFAQ
    Join Date
    Jan 2012
    Posts
    20
    The code that you have looks like it should do what you want. The $_POST['color'] variable will contain, assuming no tampering, the value of the "value" attribute of the selected radio button element with name "color" for the form submitted.

Similar Threads

  1. Giving away 2 design/programming related domain names
    By Clive in forum Promoting your Forum - Attracting New Members
    Replies: 0
    Last Post: 04-07-2008, 10:46 AM
  2. Question
    By La Grange in forum Off Topic Discussion
    Replies: 10
    Last Post: 08-08-2007, 01:22 AM
  3. Web SEO question
    By amansingh1985 in forum HTML, Design, DHTML, CSS
    Replies: 11
    Last Post: 03-25-2007, 04:31 PM
  4. 10 Programming Languages You Should Learn Right Now
    By minstrel in forum Off Topic Discussion
    Replies: 0
    Last Post: 09-16-2006, 02:44 PM
  5. Link exchange with Programming related site
    By Lovely in forum Link Building and Development
    Replies: 0
    Last Post: 10-21-2005, 10:09 AM

Posting Permissions

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