从jquery表中获取所有数据并插入到数据库中

时间:2015-11-22 15:02:06

标签: php jquery mysqli

我正在尝试从我的表中获取数据并插入数据库。问题是当我尝试插入db时,只有第一个数据进入数据库。我已经搜索了很多问题,甚至在此问过这些问题,但我并不真正理解这个过程是怎么回事。我的表格如下mytable

这是我的html脚本

 <table id="list4" class="table" width="777" border="0">
                 <thead> <tr><th>Language</th><th>Spoken</th><th>Writen</th>  </tr>
                 </thead>
                 <tbody>
                   <tr class="list4_var">
                     <td><select id="list4_Language_0" name="list4_Language_0" style="width:200px;float:left;" class="form-control">
            <option value="" selected>Please select...</option>
            <option value="Malay">Malay</option>
            <option value="English">English</option>
            <option value="Chinese">Chinese</option>
            <option value="Tamil">Tamil</option> 
          </select>
              </td>
                    <td><select id="list4_Spoken_0" name="list4_Spoken_0" style="width:200px;float:left;" class="form-control">
            <option value="" selected>Please select...</option>
            <option value="Very Good">Very Good</option>
            <option value="Good">Good</option>
            <option value="Moderate">Moderate</option>
            <option value="Bad">Bad</option>
            <option value="Very Bad">Very Bad</option>
          </select></td>
                <td><select name="list4_Writen_0" id="list4_Writen_0" style="width:200px;float:left;" class="form-control">
            <option value="" selected>Please select...</option>
            <option value="Very Good">Very Good</option>
            <option value="Good">Good</option>
            <option value="Moderate">Moderate</option>
        <option value="Bad">Bad</option>
        <option value="Very Bad">Very Bad</option>
          </select></td>
        <td class="del_area04"><button type="button" class="list4_del btn btn-danger" style="float:left;">Delete</button></td></tr>
                   </tbody>
                  </table>

这是我的php代码,我试图获取所有数据并插入db

if(isset($_POST['submit'])) {

<script type=\"text/javascript\">
var table = $("#list4 table tbody");
table.find('tr').each(function (i, el) {
        var $tds = $(this).find('td'),
            language = $tds.eq(0).text(),
            spoken = $tds.eq(1).text(),
            writen = $tds.eq(2).text();
            });
</script>

$s_language = ($_POST['list4_Language_0']);
$s_spoken = ($_POST['list4_Spoken_0']);
$s_writen = ($_POST['list4_Writen_0']);
$studentId = ($_SESSION['student']);

// attempt insert query execution
   if ( $insert = $mysqli->query ( "INSERT INTO tbllanguage (language,   spoken, writen, studentId) VALUES ('$s_language', '$s_spoken', '$s_writen', '$studentId')"))
   {
?> 
        <script>alert('Language saved ...')
        window.location='myResume.html'</script>
<?php
   }
}

0 个答案:

没有答案