使用GET提交表单时,url会有所不同

时间:2017-10-09 02:56:10

标签: php

noob问题在这里,我正在尝试检索编辑类别标签下面的输入表单中的类别标题,这是我能够做的(http://localhost:8080/cms/admin/categories.php?edit=10&title=Node%20JS)< - 输出后我点击编辑ahref(假设我点击身份证号码10),但当我尝试更改值并尝试使用提交时出现问题 submit_edit按钮网址就像这样http://localhost:8080/cms/admin/categories.php?cat_title=Test&submit_edit=Edit+Category+ 我无法使用_GET检索id,所以我可以编辑它。

<?php 
include "includes/admin_header.php"
?>

<div id="wrapper">

    <!-- Navigation -->
    <?php 
        include "includes/admin_navigation.php";
     ?>

    <div id="page-wrapper">

        <div class="container-fluid">

            <!-- Page Heading -->
            <div class="row">
                <div class="col-lg-12">

                    <h1 class="page-header">
                        Welcome to admin
                        <small>Author</small>

                    </h1>

                    <?php 
                        if(isset($_GET['submit'])){
                            $cat_title = $_GET['cat_title'];

                              $query ="INSERT INTO categories(cat_title)
                                VALUES('$cat_title')";
                                $result = mysqli_query($connection, $query);
                                if(!$result){
                                    die('Query failed'. mysqli_error());
                                }else{
                                    echo "user added into database.";
                                }
                                header("Location: categories.php");
                        }   

                     ?>

                    <?php 
                        if(isset($_GET['delete'])){
                            $cat_id = $_GET['delete'];

                            $query = "DELETE FROM categories
                                      WHERE cat_id = $cat_id";        
                            $result = mysqli_query($connection, $query);
                            if(!$result){
                                die('Query failed' . mysql_error());
                            }else{
                                echo "category $cat_id deleted";
                            }

                        }
                     ?>

                     <?php 
                     if(isset($_GET['submit_edit'])){

                        if(isset($_GET['edit']) && 
 isset($_GET['cat_title'])){
                        echo "this  condition was satisfied!";       
                             $cat_id = $_GET['edit'];    
                             $cat_title = $_GET['cat_title'];


                        $query = "UPDATE categories SET cat_title = 
 $cat_title
                                  WHERE cat_id = $cat_id";

                        $result = mysqli_query($connection, $query);

                        if(!$result){
                            die('Query Failed!'. mysqli_error());
                            }else{
                                echo "Update Complete";
                            }
                        }
                     }


                      ?>

                    <div class="col-xs-6">
                        <form action="" method="GET">
                            <div class="form-group" action="">
                                <label for="cat_title">Add Category</label>
                                <input class="form-control" type="text" 
name="cat_title" required="pls input something">
                            </div>
                             <div class="form-group">
                                <input class="btn btn-primary" type="submit" 
name="submit" value="Add Category ">
                            </div>
                        </form>

                        <form action="" method="GET">
                            <div class="form-group" action="">
                                <label for="cat_title">Edit Category</label>
                                 <?php 
                                    if(isset($_GET['edit'])){
                                        $cat_id = $_GET['edit'];

                                        $query = "SELECT *
                                                  FROM categories
                                                  WHERE cat_id = $cat_id";
                                        $result = mysqli_query($connection, 
$query);
                                        if(!$result){
                                            die('Query failed!'. 
mysqli_error());
                                        }else{
                                 ?>         <?php 
                                                while($row = 
mysqli_fetch_assoc($result)){
                                                    $cat_id = 
$row['cat_id'];
                                                    $cat_title = 
$row['cat_title'];
                                                }
                                             ?>
                                              <input type="hidden" 
name="edit" value="<?=$cat_id?>">

                                              <input  value= "<?php 
if(!isset($cat_title)){ echo "";}else{ echo "$cat_title";}
                                               ?>" class="form-control" 
type="text" name="cat_title" required="pls input something">       
                                     <?php     }
                              } ?>

                            </div>
                             <div class="form-group">
                                <input class="btn btn-primary" type="submit" 
name="submit_edit">
                            </div>
                        </form>
                    </div>   



                    <div class="col-xs-6">
                        <?php 
                            $query = "SELECT * FROM categories";
                            $result = mysqli_query($connection, $query);
                         ?>
                        <table class="table table-border table-hover">
                            <thread>    
                                <tr>
                                    <th>Id</th>
                                    <th>Category Title</th>
                                </tr>
                                <tbody>

                                    <?php
                                        while($row = 
mysqli_fetch_assoc($result)){
                                            $cat_id = $row['cat_id'];
                                            $cat_title = $row['cat_title'];?
>
                                            <tr>
                                            <?php 
                                                echo "<td>$cat_id</td>";
                                                echo "<td>$cat_title</td>";
                                                echo "<td><a 
href='categories.php?delete={$cat_id}'>delete</td>";
                                                echo "<td><a 
href='categories.php?edit={$cat_id}&title={$cat_title}'>edit</td>";
                                             ?>
                                            </tr>    

                                       <?php } ?> 


                                </tbody>
                            </thread>        
                        </table>
                    </div>



                </div>
            </div>
            <!-- /.row -->

        </div>
        <!-- /.container-fluid -->

    </div>
    <!-- /#page-wrapper -->

<?php 

    include "includes/admin_footer.php";

 ?>

1 个答案:

答案 0 :(得分:1)

将此内容放入您的编辑表单

<input type="hidden" name="edit" value="<?=$at_id?>">