0
<?php
function  createDBQuery($tableName, $condition, $cvalue,$pos) {
include('../connect.php');

$sqlStatement="select * from  $table where $condition = $cvalue";

$result = $db->prepare($sqlStatement);

$result= $result->execute(); 

for($i=0; $rowTable = $result->fetch(); $i++){


    if($rowTable)
    {
        echo $rowTable[$pos];
    }
    else
    {
        echo $rowTable[0];
    }


}       

}

Body

$cval=$row['fileID'];
$file= createDBQuery('file','fileID',$cval,'1');
//print_r($file); 
echo $file; 

Output

Call to a member function fetch() on boolean in C:\xampp\htdocs\pos\main\purchase.php:88

Mr. Pyramid
  • 3,855
  • 5
  • 32
  • 56
  • Is your `$table` in your query is the `$tableName` of your function ? – SpOOnisBacK Oct 11 '17 at 09:10
  • 1
    replace $result->fetch() with $result->fetch_array() – SNG Oct 11 '17 at 09:27
  • Your function does not [`return`](http://php.net/manual/en/function.return.php) anything, the error message makes your question a duplicate of https://stackoverflow.com/q/2973202/4265352, there is no variable called `$table` (it is `$tableName` in the function's parameters list). – axiac Oct 11 '17 at 11:20

1 Answers1

0

It looks like you're using mysqli_stmt::execute (or similar) and $result->execute() obviously returns a boolean. Aou assign it to $result and then try to call fetch() on a boolean.

Just replace $result= $result->execute(); with $result->execute();

Johannes Müller
  • 5,581
  • 1
  • 11
  • 25