0

When I'm using SQL select statements with prepared statements code works fine and display content when I'm run that in my computer localhost using WAMP server.

But when I'm upload this code to my web hosting. No any result display or no any error display.But without prepared statement code works fine in the web hosting and display results. here is my codes with and without prepared statements. Please tell me why that happens?

Code with prepared statements.

<?php 

for($i=0;$i <$count; $i++){

    require('connection.php');
    $stmt = $connection->prepare("SELECT * FROM comnt WHERE status = 'Approved' limit 1 offset ?");
    $stmt->bind_param('s', $id);
    $stmt->execute(); 
    $result = $stmt->get_result();                                          

    if($result->num_rows > 0) {
        while($row = $result-> fetch_assoc()){                          

        $pst_content = $row['content'];
        $author = $row['name'];

        if($i==0){

            echo '<div class="item active">';
            echo '      <blockquote>';
            echo '<div class="row">';
            echo '<div class="col-sm-12">';
            echo "      <p style='color:#a07936'>$pst_content</p>";
            echo "<small>$author</small>";
            echo '      </div>';
            echo '      </div>';
            echo '      </blockquote>';
            echo '      </div>';

        }else{

            echo '<div class="item">';
            echo '      <blockquote>';
            echo '<div class="row">';
            echo '<div class="col-sm-12">';
            echo "      <p style='color:#a07936'>$pst_content</p>";
            echo "<small>$author</small>";
            echo '      </div>';
            echo '      </div>';
            echo '      </blockquote>';
            echo '      </div>';                                    
        }

    }
    }
}         
?>

Code without prepared statements.

<?php 

for($i=0;$i <$count; $i++){

    require('connection.php');
    $qry = "SELECT * FROM comnt WHERE status = 'Approved' limit 1 offset $i";
    $select_cmnt = mysqli_query($connection,$qry);

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

        $pst_content = $row['content'];
        $author = $row['name'];

        if($i==0){

            echo '<div class="item active">';
            echo '      <blockquote>';
            echo '<div class="row">';
            echo '<div class="col-sm-12">';
            echo "      <p style='color:#a07936'>$pst_content</p>";
            echo "<small>$author</small>";
            echo '      </div>';
            echo '      </div>';
            echo '      </blockquote>';
            echo '      </div>';

        }else{

            echo '<div class="item">';
            echo '      <blockquote>';
            echo '<div class="row">';
            echo '<div class="col-sm-12">';
            echo "      <p style='color:#a07936'>$pst_content</p>";
            echo "<small>$author</small>";
            echo '      </div>';
            echo '      </div>';
            echo '      </blockquote>';
            echo '      </div>';                                    
        }
    }
}         
?>
Rooter
  • 383
  • 1
  • 7
  • 25
  • 1
    One thing I Noticed is this `require('connection.php');` should be written outside the for loop – Harish Sep 16 '17 at 08:24
  • @Harish yes Its my mistake,but code works fine without prepared statement. – Rooter Sep 16 '17 at 08:26
  • Yes, your code is working fine on the local server, I also checked it. have a look on this https://stackoverflow.com/questions/11575432/having-trouble-executing-a-select-query-in-a-prepared-statement maybe it can help you. – Harish Sep 16 '17 at 08:36
  • And you can also find some help over here http://php.net/manual/en/mysqli-stmt.fetch.php – Harish Sep 16 '17 at 08:38
  • Thanks @Harish I'll check – Rooter Sep 16 '17 at 08:38

0 Answers0