更新功能有什么错误?

时间:2016-08-11 22:18:56

标签: php mysql

我在我的系统中开发管理控制面板,当我在类别中更新某些未更新的数据时。我的代码有什么错误?如需更多帮助,您可以从此处http://www.mediafire.com/download/m9psmr55pib5555/update_category.rar

下载我的文件
<form action="categories.php" method="post">
          <label>Edit category</label>
            <?php
              /*start of select data   */
                 if(isset($_GET['edit_cat'])){
                $cat_id     = $_GET['edit_cat'];
                $update_cat ="SELECT * FROM categories WHERE cat_id= $cat_id";
                $run_cat_id = mysqli_query($connect , $update_cat);
                while($row  =mysqli_fetch_assoc($run_cat_id)){
                    $cat_id    =  $row['cat_id'];
                    $cat_title =  $row['cat_name'];         
?>   
    <div class="form-group">
<!--to pick the value   -->
          <input value="<?php if(isset($cat_title)){echo $cat_title;} ?>" type="text" class="form-control" name="cat_name">
          </div>

<?php }}?>            

          <?php
                if(isset($_POST['update'])){
                    $cat_update  = $_POST['cat_name'];
                    $query ="UPDATE categories SET cat_name ='{$cat_update}' WHERE cat_id ={$cat_id}";
                    $update_query= mysqli_query($connect , $query);
<?php 
ob_start();
include("includes/header.php");
include("includes/db.php");
?>
<div id="page-wrapper">
    <div class="container-fluid">
        <?php
           if(isset($_GET['edit_cat'])){
           $cat_id = $_GET['edit_cat'];
            include ("includes/update_category.php");
        }
        ?>
    </div>      
<!-- end of category form -->
</div>               
<!--
===========================================================================================================
-->

        <!--  start of table  to show categories-->
        <div class="col-lg-6">
        <div class="btn btn-success"><h3>categories</h3></div>
                        <div class="table-responsive" >
                            <table class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th width="10px">Id</th>
                                        <th width="400px">category title</th>
                                    </tr>
                                </thead>
                                <tbody>

                                    <?php
                                    /*Select from DB to show categories in table*/
                                    $i=1;
                                    $query   = "SELECT *FROM categories";
                                    $run_cat = mysqli_query($connect , $query);
                                    while($row = mysqli_fetch_assoc($run_cat)){
                                        $cat_id   = $row['cat_id'];
                                        $cat_name =$row ['cat_name'];

                                        ?>
                                        <tr>
                                        <td><?php echo $i++;?></td>
                                       <td><?php echo $cat_name; ?></td>
                                        <td><a href="categories.php?edit_cat=<?php echo $cat_id;?>"><div class='btn btn-warning' name="edit_cat"><i class='fa fa-pencil-square-o fa-2'></i> Edit</div></a></td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>

                        </div>  

    <!--  end of table  to show categories-->
<!-- =============================================================================
-->

  </div>

  </div>
</div>

</body>

</html>



                    if(!$update_query){
                        die("QUERY FAILED".mysqli_error($connect));
                    }
                }
          ?>
            <div class="form-group">
             <input  type="submit" name="update"  value="submit" class="btn btn-success"/>
            </div>
        </form> 

0 个答案:

没有答案