-3

i am not getting any result ..tried a lot ...but didnt know what is the problem.

no results after editing...nothing changed ...and is also not showing any error..please help..i need to submit a project.' Thankyou.

<form action="acat.php" method="post">  <!--Edit cat form-->
                        <div class ="form-group">
                            <label for ="title">Edit Category</label>


<?php

 if(isset($_GET['edit'])) {

  $editid = $_GET['edit']; 


  if (!$editid) {

  echo "CANNOT BE EDITED";

   } else { 
      $query = "SELECT * FROM categories WHERE cat_id = '$editid'"; 


     $edit_query = mysqli_query($con,$query); 

     }

    while($row=mysqli_fetch_assoc($edit_query)) {            

     $cat_id = $row['cat_id'];
     $cat_title = $row['cat_title'];

       ?>
       <input value="<?php if(isset($editid)) {echo $cat_title;} ?>"                                  
         class="form-control" type="text" name="update">                                                      

  <?php } } ?> 

 <?php
    if(isset($_POST['update_submit'])  && isset($_GET['edit'])) {

                $editid = $_GET['edit']; 
                $updatetitle = $_POST['update'];

          $query = "UPDATE categories SET cat_title='$updatetitle' where    
                 cat_id='$editid'";

          $update_query = mysqli_query($con,$query);

             if (!$update_query) {

          die('QUERY FAILED' . mysqli_error($con));
               }
           }

               ?>


                      </div>

                        <div class="form-group">
                           <input class="btn btn-primary"  type="submit" 
                             name="update_submit" value="Update Category">   
                         </div>
                         </form>

                        </div> 
  • 1
    Use prepared Statements to prevent SQL injection – Jens Mar 22 '17 at 07:31
  • Which line is `acat.php on line 107 ` – Jens Mar 22 '17 at 07:32
  • i have commented as error line –  Mar 22 '17 at 07:42
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Jonnix Mar 22 '17 at 08:57

1 Answers1

1

In the POST condition, it's unable to identify $editid

Change this line:

if(isset($_POST['update_submit'])) {

To this:

if(isset($_POST['update_submit']) && isset($_GET['edit'])) {

    $editid = $_GET['edit']; // Add this line
    $updatetitle = $_POST['update'];

    $query = "SELECT * FROM categories  SET cat_title='$updatetitle' WHERE 
 cat_id = '$editid'";      //error line              
    $update_query = mysqli_query($con,$query);
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32