0

我的页面中有一个表,它的前两列来自数据库中的一个表,第三列是复选框,如果用户知道表中显示的单词的含义,请检查它们我想更新我的表数据库以这种方式:对于选中的复选框,将 1 插入到表中的检查列中,否则插入 0 我如何获取复选框值并将其插入数据库中的右行直到现在我有这段代码:

    <?php
        $con = mysql_connect("localhost", "root", "")
        or die(mysql_error());   
        if (!$con) { 
            die('Could not connect to MySQL: ' . mysql_error()); 
        } 
        mysql_select_db("project", $con)
        or die(mysql_error());
        $result = mysql_query("select * from words");
        echo "<table border='1'>
           <tr>
              <th>word</th>
              <th>meaning</th>
              <th>checking</th>
            </tr>";
            while($row = mysql_fetch_array($result)) {
                  echo "<tr>";
                    echo "<td>" . $row['word'] . "</td>";
                    echo "<td>". "<div class='hiding' style='display:none'>".$row['meaning']."</div>"."</td>";
                    echo "<td>";
                     echo "<input name=\"fahimeh\" type=\"checkbox\" value=\"\"> ";
                    echo "</td>";
                  echo "</tr>";
                  }
         echo "</table>";
         mysql_close($con);                        
        ?>
        <button onclick="ShowMeanings()">ShowMeanings</button>
        <button onclick="feedback()">sendfeedback</button>  

这是我的javascript代码:

   <script type="text/javascript">
        function ShowMeanings(){
        var hidings = document.getElementsByClassName('hiding');
        for (var i=0; i<hidings.length; i++){
        hidings[i].style.display = 'block';
        }

        }
    </script>

我不知道如何编写反馈(),以及如何获取复选框值并将其插入数据库的右行

4

1 回答 1

0

这应该工作:)

<?php
        $con = mysql_connect("localhost", "root", "")
        or die(mysql_error());   
        if (!$con) { 
            die('Could not connect to MySQL: ' . mysql_error()); 
        } 
        mysql_select_db("project", $con)
        or die(mysql_error());
        $result = mysql_query("SELECT * FROM words");
        echo "<table border='1'>
           <tr>
              <th>word</th>
              <th>meaning</th>
              <th>checking</th>
            </tr>";
            while($row = mysql_fetch_array($result)) {
                  echo "<tr>";
                    echo "<td>" . $row['word'] . "</td>";
                    echo "<td>". "<div class='hiding' style='display:none'>".$row['meaning']."</div>"."</td>";
                    echo "<td>";
                     echo "<input name=\"fahimeh\" type=\"checkbox\" name='" . $row['id'] . "' value=\"\"> ";
                    echo "</td>";
                  echo "</tr>";
                  }
         echo "</table>";
         mysql_close($con);                        
        ?>
        <button onclick="ShowMeanings()">ShowMeanings</button>
        <button onclick="feedback()">sendfeedback</button>  
于 2013-10-10T16:25:33.923 回答