0

error message i have an undefined index error in my sortdis.php code, it took me hour to solve so i posted my question here, hope anyone can fix this for me thankyou. error says Undefined index: column_name and mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean both given in sort.php

index.php

<?php  
 
 $connect = mysqli_connect("localhost", "root", "", "testing");  
 $output = '';  
 $order = $_POST["order"];  
 if($order == 'desc')  
 {    
      $order = 'asc';  
 }  
 else  
 {  
      $order = 'desc';  
 }  
 $query = "SELECT * FROM driver ORDER BY ".$_POST["column_name"]." ".$_POST["order"]."";  
 $result = mysqli_query($connect, $query);  
 $output .= '  
 <table class="table table-bordered">  
      <tr>  
           <th><a class="column_sort" id="Driver_ID" data-order="'.$order.'" href="#">ID</a></th>  
           <th><a class="column_sort" id="Driver_fullname" data-order="'.$order.'" href="#">Name</a></th>  
           <th><a class="column_sort" id="Contact_No" data-order="'.$order.'" href="#">Contact No.</a></th>  
          
      </tr>  
 ';  
 while($row = mysqli_fetch_array($result))  
 {  
      $output .= '  
      <tr>  
           <td>' . $row["Driver_ID"] . '</td>  
           <td>' . $row["Driver_fullname"] . '</td>  
           <td>' . $row["Contact_No"] . '</td>  
            
      </tr>  
      ';  
 }  
 $output .= '</table>';  
 echo $output;  
 ?>  

AND THIS IS MY sort.php code: `

  <?php   
 $connect = mysqli_connect('localhost', 'root', '', 'testing');  
 $query = "SELECT * FROM driver ORDER BY Driver_ID DESC";  
 $result = mysqli_query($connect, $query);  
 ?>  
 <!DOCTYPE html>  
 <html>  
      <head>  
           <title>SORT MO TO! XDD</title>  
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
      </head>  
      <body>  
           <br />            
           <div class="container" style="width:700px;" align="center">  
                <h3 class="text-center">SORT 101</h3><br /><div class="table-responsive" id="driver">  
                     <table class="table table-bordered">  
                          <tr>  
                               <th><a class="column_sort" id="Driver_ID" data-order="desc" href="#">ID</a></th>  
                               <th><a class="column_sort" id="Driver_fullname" data-order="desc" href="#">Name</a></th>  
                               <th><a class="column_sort" id="Contact_No" data-order="desc" href="#">Contact No.</a></th>  
                              
                          </tr>  
                          <?php  
                          while($row = mysqli_fetch_array($result))  
                          {  
                          ?>  
                          <tr>  
                               <td><?php echo $row["Driver_ID"]; ?></td>  
                               <td><?php echo $row["Driver_fullname"]; ?></td>  
                               <td><?php echo $row["Contact_No"]; ?></td>  
                          </tr>  
                          <?php  
                          }  
                          ?>  
                     </table>  
                </div>  
           </div>  
           <br />  
      </body>  
 </html>  
 <script>  
 $(document).ready(function(){  
      $(document).on('click', '.column_sort', function(){  
           var column_name = $(this).attr("Driver_ID");  
           var order = $(this).data("order");  
           var arrow = '';  
           //glyphicon glyphicon-arrow-up  
           //glyphicon glyphicon-arrow-down  
           if(order == 'desc')  
           {  
                arrow = '&nbsp;<span class="glyphicon glyphicon-arrow-down"></span>';  
           }  
           else  
           {  
                arrow = '&nbsp;<span class="glyphicon glyphicon-arrow-up"></span>';  
           }  
           $.ajax({  
                url:"sortdis.php",  
                method:"POST",  
                data:{column_name:column_name, order:order},  
                success:function(data)  
                {  
                     $('#driver').html(data);  
                     $('#'+column_name+'').append(arrow);  
                }  
           })  
      });  
 });  
 </script>  

`

1 Answers1

0

Please visit the error log. You will be able to get the line number where you are getting the issue. From that line number you will identify the spot where you are making mistake

Click here to check that from where you can find the error logs