索引在第二个PHP代码块中未定义

时间:2014-02-01 19:14:41

标签: php

在这里它显示标题是undefined.Title自带查询.Id上传URL。然后我使用给定的id获取数据。

代码

 <?php
    $id = isset($_REQUEST['Id']) ? $id = $_REQUEST['Id'] : '';
    if ($id != 0) {
        include('config.php');
        $sql = "SELECT Id,Title,description,Image,Category from News WHERE Id='" . $id . "'";
        $query = mysql_query($sql);
        $row = mysql_fetch_array($query);
       ?>

        <form action="edit.php" method="POST" enctype="multipart/form-data">

            <div class="OuterWrapper" background-color:white; >
                 <div class="row" id="wrapper" >
                    <div class="col-xs-3" style="margin-top:5%">
                        Title
                    </div>
                    <div class="col-xs-3" style="margin-top:5%">
                        <input type="hidden" name="Title" class="form-control" value="<?php echo $row[0] ?>" >
                        <input type="text" name="Title" class="form-control" value="<?php echo $row[1] ?>" >
                    </div>
                            //SOME HTML CODE HERE


                        </form>

                       <?php 


                        $Title = mysql_real_escape_string($_POST["Title"]);  <-- Undefined Index 'Title'

                        //$description_save = $_POST['description'];
                        //$Category  = $_POST["select_category"];
                        mysql_query("UPDATE News SET Title ='$Title', Description ='$description_save' WHERE Id = '$id'") or die(mysql_error());
                        //echo "Succesfully Updated!";
                        //header("Location: list.php");
                    }
                    ?>

                    </body>
                    </html>

1 个答案:

答案 0 :(得分:2)

您需要测试Title是否实际设置。发生该错误是因为没有发送带有该数据的请求。

if(isset($_POST['Title'])) $Title = mysql_real_escape_string($_POST['Title']);

如果它仍然不起作用,则表示您通过

发送数据的方式有问题