-1

我有这两个文件,我正在更新一个表,但是在 update.php 文件上我收到错误消息 Notice: Undefined index: pname , $pcode......$pname = $_POST["pname"];这里我将 pname 值存储在 pname 变量中。但它显示错误

                        <address>

                           <div class="control-group">



                                    <label class="control-label">Product Name:</label>
                                    <div class="controls">
                                        <input id="pname" name="pname" type="text" value="<?php echo $PName; ?>"
                                        class="input-xlarge">
                                        <p class="help-block"></p>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">Product Code:</label>
                                    <div class="controls">
                                        <input id="code" name="pcode" type="text"  value="<?php echo $PCode; ?>"
                                        class="input-xlarge">

                                    </div>
                                </div>


                                <div class="control-group">
                                    <label class="control-label">Product Price:</label>
                                    <div class="controls">
                                        <input id="price" name="pprice" type="text" value="<?php echo $PPrice; ?>"
                                        class="input-xlarge">

                                    </div>
                                </div>


                            <div class="control-group">
                                    <label class="control-label">Availability:</label>
                                    <div class="controls">
                                        <select id="stock" name="stock" class="input-xlarge">

                                            <option value="1" selected="selected">Available</option>
                                            <option value="0">Not Available</option>

                                        </select>
                                    </div>
                          </div>

                              <div class="control-group">
                                    <label class="control-label">Product Description:</label>
                                    <div class="controls">
                                        <textarea rows="4" cols="50" name="description" > <?php echo $PDescription; ?> </textarea>
                                    </div>
                          </div>


                               <div class="control-group">
                                    Picture 1 :
                                    <div class="controls">
                                     <input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
                                    <input  type="file" name="pic1"
                                        class="input-xlarge">

                                    </div>
                          </div>

                           <div class="control-group">
                                    Picture 2 :
                                    <div class="controls">
                                     <input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
                                    <input  type="file" name="pic2"
                                        class="input-xlarge">

                                    </div>
                          </div>


                             <div class="control-group">
                                    Picture 3 :
                                    <div class="controls">
                                     <input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
                                    <input  type="file" name="pic3"
                                        class="input-xlarge">

                                    </div>
                          </div>


                              <div class="control-group">

                                    <div class="controls">
                                    <input type='hidden' name='id' value="<?php echo $ID; ?>"><br/>
                                        <input type="submit" value="UPDATE" class="btn-large" />

                                    </div>
                                </div>


                              </form>
4

2 回答 2

0

你检查表单提交吗?

if (isset($_POST["pname"])) {
    // do all your form processing here.
}
于 2013-09-16T20:06:00.473 回答
0
$pname= (isset($_POST["pname"]) ? $_POST["pname"] : ""); 

这将检查 pname 是否存在于 $_POST 中,然后设置它。

您收到该错误是因为您没有设置 $_POST["pname"]

于 2013-09-16T20:08:19.813 回答