I am creating a web survey to collect data for a grad project/paper and am collecting the data into a MySQL database. What the webpage is supposed to do is the following: Respondents will see a word and then have to make one of four choices. Three choices are radio buttons and the fourth choice is "other" where they will have an opportunity to enter something into a text box. This seems to be a fairly typical set-up, but I am having trouble on the sql end of things.
The problem is that, although the web page seems to function properly, when I look at the database, none of the radio button values are present-- the only values that are passed to the sql server are those entered into a text box (including blank values where a radio button was checked and nothing was entered into the text box.
The code for creating the survey page is:
echo "<form action='insert2.php' method='post'>";
echo " <table border='1' cellpadding = '10' align = 'center'>
<tr>
<th>Num</th>
<th>Français</th>
<th>Choix 1</th>
<th>Choix 2</th>
<th>Choix 3</th>
<th>Choix 4</th>
</tr>";
for ($i=1; $i<=$total; $i++)
{
$query = "SELECT * FROM MyDataTable WHERE id = '$i'";
$word = $db->query($query);
$word = $word->fetch();
echo "<tr>";
echo "<td>" . "$i " . "</td>";
echo "<td width = '300'>" . $word[1] . "</td>";
echo "<td width = '300' align = 'center'>" .
" <input type='radio' name='word$i' value='one' id='wa_$i' /> " . $word[2] . "</td>";
echo "<td width = '300' align = 'center'>" .
" <input type='radio' name='word$i' value='two' id='wb_$i' /> " . $word[3] . "</td>";
echo "<td width = '300' align = 'center'>" .
" <input type='radio' name='word$i' value='three' id='wc_$i' /> " . $word[4] . "</td>";
echo "<td width = '300' align = 'center'>" .
" autre: <input type='text' name='word$i' id='wd_$i' /> </td>";
echo "</tr>";
}
echo "<br /><br />";
echo "</table>";
Everything works fine when I don't have the final form field (the textbox). Is it not possible to EITHER a radio button value OR a textbox value?
The 'insert2.php' code is as follows:
mysql_query("INSERT INTO `MyResultsTable` (w1) VALUES ('$_POST[word1]')");
$last_id = mysql_insert_id();
for ($i=2; $i<=$total; $i++)// This loop inserts the rest of the data into the DB
{
$temp = "word$i";
if (isset($_POST[$temp]))
{
mysql_query("UPDATE `MyResultsTable` SET w$i='$_POST[$temp]' WHERE id = $last_id");
}
Any help would be greatly appreciated. I'm new at this and have searched for a long time, but to no avail.
Regards,
Matt