未定义的索引:第13行的C:\ wamp \ www \ cdij \ insert.php中的text_unitcost

时间:2013-03-06 12:23:32

标签: php html

我正在尝试将值插入表中。但我收到一个错误:  未定义的索引:第13行的C:\ wamp \ www \ cdij \ insert.php中的text_unitcost

插入页面是所有值为Going的页面,这是插入页面:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script language="JavaScript" src="myminiAJAX.js"></script>
<script language="JavaScript" src="functions.js"></script>
</head>
<body>
To Insert a new part<br/>
<form name="insert_values" action="insert.php" method="post">
    Select The Category<select name="combo_category" id="combo_category" onChange="doAjax('fill_combo_insertpart_combo_assembly.php', 'combo_category='+getValue('combo_category'), 'populate_combo_insertpart_combo_assembly', 'post', '1')">
    <option value="-1">--Please Select--</option>
    <option value="Brake">Brake</option>
    <option value="Fastner">Fastner</option>
    <option value="Suspension">Suspension</option>
    <option value="-1">--Please Select--</option>
    <option value="-1">--Please Select--</option>
    <option value="-1">--Please Select--</option>
    <option value="-1">--Please Select--</option>
    <option value="-1">--Please Select--</option>
    </select><br/><br/>
    Select The Assembly<select name="combo_assembly" id="combo_assembly" onchange="doAjax('fill_combo_index_and_indexpart_combo_part.php', 'par='+getValue('combo_assembly'), 'populate_combo_index_and_insertpart_part', 'post', '1')">
    <option value="-1">--Please Select--</option>
    </select><br/><br/>
    Select The Part:<select name="combo_part" id="combo_part">
    <option value="-1">--Please Select--</option>
    </select><br/><br/>
    Where Do you want to Insert?<br/><br/>
    Material<input type="radio" name="radio_insert_table" value="material" onclick="create_form_insertpart_material();doAjax('fill_combo_indexpart_combo_material.php','','populate_combo_insertpart_combo_material','post','1')"/>
    Process<input type="radio" name="radio_insert_table" value="process" onclick="create_form_insertpart_process();doAjax('fill_combo_indexpart_combo_process.php', '', 'populate_combo_insertpart_combo_process', 'post', '1');doAjax('fill_combo_indexpart_combo_multiplier.php', '','populate_combo_insertpart_combo_multiplier', 'post', '1')" />
    Fastner<input type="radio" name="radio_insert_table" value="fastner"/>

    <div id="form" ></div>
    <br/><br/>
    <input type="submit" name="ipsubmit" value="Submit"/>
</form>
</body>
</html>

在“<div id="form">”中,根据使用javascript的单选按钮选择创建了一些新字段。以下是代码:

function create_form_insertpart_process() {
    document.getElementById("form").innerHTML="<select name=\"combo_process\" id=\"combo_process\" onChange=\"doAjax('fill_combo_indexpart_combo_process.php','process_name='+getValue('combo_process'),'populate_textbox_insertpart_process_unticost_and_unit','post','1')\"><option value=\"-1\">--Please Select--</option></select><br/><br/> ";
    document.getElementById("form").innerHTML+="<input type=\"text\" name=\"text_use\" id=\"text_use\" />";
    document.getElementById("form").innerHTML+="<input type=\"text\" name=\"text_unitcost\" id=\"text_unitcost\" disabled=\"disabled\" />";
    document.getElementById("form").innerHTML+="<input type=\"text\" name=\"text_unit\" id=\"text_unit\" disabled=\"disabled\" />";
    document.getElementById("form").innerHTML+="<input type=\"text\" name=\"text_quantity\" id=\"text_quantity\" />";
    document.getElementById("form").innerHTML+="<select name=\"combo_multiplier\" id=\"combo_multiplier\" onChange=\"doAjax('fill_combo_indexpart_combo_multiplier.php','multiplier_name='+getValue('combo_multiplier'),'populate_textbox_insertpart_multiplier_value','post','1')\"><option value=\"-1\">--Please Select--</option></select><br/><br/> ";
    document.getElementById("form").innerHTML+="<input type=\"text\" name=\"text_multipliervalue\" id=\"text_multipliervalue\" disabled=\"disabled\"/>";
    window.setInterval("calculate_textbox_insertpart_text_subtotal()",10);
    document.getElementById("form").innerHTML+="<input type=\"text\" name=\"text_subtotal\" id=\"text_subtotal\"  disabled=\"disabled\" />";

}

在上面的代码中:

document.getElementById("form").innerHTML+="<input type=\"text\" name=\"text_unitcost\" id=\"text_unitcost\" disabled=\"disabled\" />";

此字段的值由javascript函数生成,该函数使用AJAX和XML从服务器返回数据库

最后这里是我编写代码以将值插入数据库

的页面
<?php
    include("dbconfig.inc.php");
     $combo_category=$_POST['combo_category'];
     $combo_assembly=$_POST['combo_assembly'];
     $combo_part=$_POST['combo_part'];
     $radio_insert_table=$_POST['radio_insert_table'];
     if($radio_insert_table=="material") {

     }
     else if($radio_insert_table=="process") {
        $combo_process=$_POST['combo_process'];
        $text_use=$_POST['text_use'];
        $text_unitcost=$_POST['text_unitcost'];
        //$text_unit=$_POST['text_unit'];
        //$text_quantity=$_POST['text_quantity'];
        //$combo_multiplier=$_POST['combo_multiplier'];
        //$text_multipliervalue=$_POST['text_multipliervalue'];
        ////$text_subtotal=$_POST['text_subtotal'];
        $select=$dbh->prepare('INSERT INTO process (process_unitcost) values(:text_unitcost)');
        //$select->execute(array(':text_unitcost' => $text_unitcost));

     }
?>

在上面的代码中,我在第13行收到错误,因为未定义索引text_unitcost

提前感谢您的帮助

1 个答案:

答案 0 :(得分:0)

如果您发布已禁用且没有值的INPUT字段,则它们不会被发布,因此没有为这些字段设置索引。

禁用字段未发布,如果您想要显示但不允许编辑,则应使用readonly="readonly"

参考http://www.w3.org/TR/html4/interact/forms.html#h-17.12