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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Stuck with while

    I have assigned the question_id to the radio boxes names so I can post them in an array and also differentiate. I'm stuck at $posted_answer = $_POST[$qID];, I want the radio values for each qID to be stored in that variable($posted_answer) and somehow I can convert those values into an array.

    Any ideas? If I'm not clear, please let me know.

    If there's a better way, do let me know.


    PHP Code:
    <?php

    // Last Modified 17th August

    include('templates/header.php'); // Header template
    include('config/config.php'); // Includes configuration files
    include('lib/functions.php'); // Load all functions from Library

    $select_questions mysql_query("SELECT * FROM questions") or die(mysql_error());
    echo 
    "<form method=\"post\">";
    while(
    $row mysql_fetch_array($select_questions)){
        
    $questions $row['question'];
        
    $qID $row['id'];
        echo 
    $questions."<br/>For: <input type=\"radio\" value=\"For\" name=\"".$qID."\"><br/>Against: <input type=\"radio\" value=\"Against\" name=\"".$qID."\"><br/><br/>";
        
    $posted_answer $_POST[$qID];
        
    $submit_useranswer $_POST['submit_useranswers'];
    }

    echo 
    "<input type=\"submit\" name=\"submit_useranswers\">";
    echo 
    "</form>";

    if(isset(
    $submit_useranswer)){
        
    $user_answer = array($posted_answer);
        
    print_r($user_answer);
    }

    include(
    'templates/footer.php'); // Footer Template

    ?>

  • #2
    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
    The $_POST array is an empty array until your form is submitted back to your page.

    Once your page is submitted, the array you desire will be there and it's called $_POST-- no need to create a separate array (unless you really want to).


  •  

    Posting Permissions

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