0

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

插入页面是所有值都经过的页面,这是插入页面:

<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

提前感谢您的帮助

4

1 回答 1

0

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

禁用的字段不会被发布,readonly="readonly"如果您想显示它但不允许编辑,您应该使用它。

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

于 2013-03-06T12:27:03.710 回答