Click here to Skip to main content
13,795,118 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have a table named tbl_video that consist of two fields (video_id, video_title What I want to add a load more button using Ajax JQuery like social networking sites .I am able to get the first four records but when I try to get the othersthen I am getting this exception .What am i doing wrong .

What I have tried:

this my index.php file I create table structure here and then fetch records.



    <pre lang="php">



     <pre>   <table class="table table-bordered" id="load_data_table"> 

                    <thead>
                    <tr>
                    <td width="15%">Video Id</td>
                    <td>Video Title</td>
                    </tr>
                    </thead>
                    <?php

                    while ($row = mysqli_fetch_array($result)) {
                        $video_id = $row['video_id']; ?>
                             <tr>
                             <td><?php echo $row['video_id']; ?></td>
                             <td><?php echo $row['video_title']; ?></td>

                             </tr>
                        <?php
                    }

                    ?> 
                    <tr id="remove_row"><td><button type="button" class="more btn btn-success form-control"
                     data-id="<?php echo $video_id; ?>">More</button></td></tr>
                       
                    </table>  
               </div>  






<script>

function moreButton(){

   $('.more').click(function(){
       
    var id=$(this).data("id");


$.ajax({
    url:"more.php",
    data:{id:id},
    method:"post",
    success:function(data){

      if(data!=''){

       $('#load_data_table').append(data);
       $('#remove_row').remove();

         moreButton();
      }
      else{
        $('.more:last').html("No Data");
      }
    }
 });

    });
 
}

 $(document).ready(function(){  

moreButton();
});

and this the more.php file.I think it is self explanatory


<?php

ini_set('display_errors', 1);
$id = $_POST['id'];
$output = '';
$db = mysqli_connect('localhost', 'root', '', 'testing');
$data = mysqli_query($db, "select * from tbl_video where video_id >{$id} limit 2");
if (mysqli_num_rows($data)) {
    while ($row = mysqli_fetch_array($data)) {
        $output .= '
         
         <tbody>
         <tr>
          <td>'.$row['video_id'].'</td>
          <td>'.$row['video_title'].'</td>
         </tr>
        
         ';
    }
    $output .= '<tr id="remove_row"><td><button type="button"  class="more btn btn-success form-control" data-id="'.$row['video_id'].'">More</button></td></tr></tbody>';
    echo $output;
}





any help would be appriciated.
Posted 13-Oct-18 5:07am
Updated 13-Oct-18 6:16am
Comments
Richard Deeming 16-Oct-18 12:16pm
   
$data = mysqli_query($db, "select * from tbl_video where video_id >{$id} limit 2");

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
PHP: SQL Injection - Manual[^]

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

$data is returning false. Your query has an error in it


Remove this and add this

select * from tbl_video where video_id > ."$id." limit 2
  Permalink  
v2
Comments
Member 3722539 15-Oct-18 4:03am
   
thank you
summiya1 15-Oct-18 6:18am
   
you welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.181207.3 | Last Updated 13 Oct 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100