View Full Version : Stuck with while

08-17-2007, 11:03 PM
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.


// 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>";

$user_answer = array($posted_answer);

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


08-19-2007, 09:03 AM
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).