我使用一个表单,当我选择第一个选项时,我使用javascript填充第二个下拉菜单。一切都很好,在形式第二溺水是改变和显示结果取决于我的选择。但是在提交了第二个下拉菜单的值之后,并没有被插入到mysql中。它的空白。
这是我的表格代码。

<style type="text/css">
table,tr,td{border:0px solid black;}
</style>
  <table id="titlebar" cellspacing="0px">
        <tr>
            <td style="width:20px;">&#10003;</td>
            <td style="width:160px;">Show</td>
            <td style="width:62px;">season</td>
            <td style="width:63px;">episode</td>
            <td style="width:100px;">language</td>
            <td style="width:190px;">Link 1</td>
        </tr>
    </table>
    <form action="send.php" method="POST">
  <table id="dataTable" width="auto" style="margin:-4px 0 0 0;" cellspacing="0px">
    <tr>
      <td style="width:20px;"><INPUT type="checkbox" name="chk" /></td>
      <td><select name="series[]" onchange="showUser(this.value)"> <?php echo $item; ?></select></td>
            <td><select name="season[]" id="txtHint"> </ </select></td>
               </tr>
  </table>
    <INPUT type="button" value="Add row" onclick="addRow('dataTable')" />
  <INPUT type="button" value="Delete row" onclick="deleteRow('dataTable')" />
    <INPUT type="submit" name="submit" value="submit"/>
    </form>

这是我的javascrip更改下拉菜单
<script  src="jquery.min.js"></script>

<script>
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>

这是我的邮政编码
发送.php
<?php

    include('mysql.php');

     if (isset($_POST['submit']))
        {
            $stockid = $_POST["series"];
            $desc = $_POST["season"];

            foreach($stockid as $a => $B)
            {

        mysql_query("INSERT INTO 0_stock_master (stock_id, description, long_description) VALUES ('$stockid[$a]','$desc[$a]')");
    }
    }
    ?>

我的问题是它正在插入$stockid[$a],而不是插入$desc[$a]。。。。。

最佳答案

这是因为查询中有错误

mysql_query("INSERT INTO 0_stock_master
  (stock_id, description, long_description)
  VALUES
 ('$stockid[$a]','$desc[$a]')");

您试图添加3个字段,但在值中只指定了2个结果mysql错误。

09-30 17:25
查看更多