Getting error in all write requests with prepared mysqli operations

In my code to search for a record, I get an error during the lock, it does not retrieve the record. I did not use bind_result because the number of columns to retrieve is 45. Please help me where I am wrong.

<?php 
/* ___Search & display record with MySQLi Prepared Statements ___*/

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

$cname=$_GET['cname'];
$cname=preg_replace( '/\s+/','',$cname);
if($cname==""){
    unset($cname);
    $error="Plese enter the company name";
}
else {  
        require_once '../includes/mysqli_dbconnect.php';
        $cname = '%'.$cname.'%';
        $query1 = "SELECT * FROM company WHERE cname LIKE ? ORDER BY cname DESC";
        $stmt=$dbLink->prepare($query1);
        if($stmt===false){
            trigger_error('Query Failed'. $query1 . 'Error: ' . $dbLink->error, E_USER_ERROR);
        }
        $stmt->bind_param('s',$cname);
        $stmt->execute();
        $stmt->store_result();
        if($stmt->num_rows > 0 ){
            $rs=$stmt->get_result();
            while($row=$rs->fetch()){
                                  //here number of columns to show are 45.
                echo 'ID: '. $row['id']. '<br/>';
                echo 'Company: '. $row['cname']. '<br/>';
            }
        }else{
                echo 'No Record Found';
            } 
        $stmt->close(); 
        $dbLink->close();
      }
 }
 ?> 
+3
source share
1 answer

Before you enter the while loop, I would recommend that you check to see if you are actually receiving any data. Try to output any result obtained from the query first:

var_dump ($ RS-> fetch_all ());

0
source

All Articles