Results 1 to 2 of 2

Thread: PHP Programming question regarding if statements?

  1. #1
    New to vBFAQ
    Join Date
    Dec 2009

    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">
    <input type="text" name="name" id="name" />


    <input type="text" name="age" id="age" />

    Be prepared to answer some difficult questions!

    How do you feel? </label>
    <input type="radio" name="emotion" value="happy" id="happy" />
    happy </label>

    <input type="radio" name="emotion" value="sad" id="sad " />

    <input type="radio" name="emotion" value="angry" id="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>

    <input type="radio" name="reason" value="you have no life" id="life" />
    you have no life</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>What is your favorite color?</p>
    <input type="radio" name="color" value="red" id="red" />

    <input type="radio" name="color" value="yellow" id="yellow" />

    <input type="radio" name="color" value="green" id="green" />

    <input type="radio" name="color" value="blue" id="blue" />

    <input type="radio" name="color" value="orange" id="orange" />

    <label>What is your favorite season?

    <input type="radio" name="season" value="autumn" id="autumn" />
    autumn </label>

    <input type="radio" name="season" value="spring" id="spring" />

    <input type="radio" name="season" value="summer" id="summer" />

    <input type="radio" name="season" value="winter" id="winter" />


    What is your favorite genre of music?

    <input type="radio" name="music" value="rock" id="rock" />

    <input type="radio" name="music" value="hip-hop" id="hip-hop" />
    hip-hop </label>

    <input type="radio" name="music" value="dance" id="dance" />

    <input type="radio" name="music" value="pop" id="pop" />

    <input type="radio" name="music" value="alternative" id="alternative" />


    <input type="submit" name="button_1" id="button_1" value="Submit" />




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