duandun2218 2012-05-29 20:46
浏览 30

文本框覆盖MySQL中的单选按钮

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&ccedil;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

  • 写回答

1条回答 默认 最新

  • doujingxi3356 2012-05-31 00:50
    关注

    Change your radios to

    <input type='radio' name='word$i[]' value='one' id='wa_$i' />
    <input type='radio' name='word$i[]' value='two' id='wb_$i' />
    <input type='radio' name='word$i[]' value='three' id='wc_$i' />
    

    (Notice the array brackets after the value in the "name" property)

    And see if that fixes it.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么