url is different when submitting a form using GET

noob question here, i'm trying to retrieve the category title in the input form below the Edit Category label, which is im able to do (http://localhost:8080/cms/admin/categories.php?edit=10&title=Node%20JS) <- output after i click the edit ahref (assuming i click the Id number 10), but the problem when i try to change the value and try to submit it using the submit_edit button the url comes like this http://localhost:8080/cms/admin/categories.php?cat_title=Test&submit_edit=Edit+Category+ which is i cant retrieve the id using the _GET so i can edit it.

<?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";

 ?>

put this inside your edit form,

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

0 Comment

NO COMMENTS

LEAVE A REPLY

Captcha image