php - Call to a member function bindParam on a non-object -


this question has answer here:

i'm trying different sql statement in case user submit search form. i'm trying code below, i'm getting error , i'm not understanding why, because code seems gode me.

do see here can cause of these errors?

errors im getting:

call member function bindparam() on non-object in $readnews->bindparam

notice: undefined variable: readnews in $readnews->bindparam(':begin', begin, pdo::param_int);

fatal error: call member function bindparam() on non-object in f:\xampp\htdocs\projeto\admin\posts\noticias.php on line 53

my code:

$pag = (empty($_get['pag']) ? '1' : $_get['pag']); $maximo = 5;  $begin = ($pag * $max) - $max;     if (isset($_post['search']))  { $search = $_post['search']; if(!empty($search) && $search != 'title:') { $readnews = $pdo->prepare("select * news title concat('%', :search, '%') order data desc limit :begin, :max"); $readnews->bindparam(':search', $search); } }        else { $readnews = $pdo->prepare('select * news order data desc limit :begin, :max'); }  $readnews->bindparam(':begin', begin, pdo::param_int); $readnews->bindparam(':max', $max, pdo::param_int); $readnews->execute(); $resultreadnews = $readnews->rowcount(); 

you not handling 1 case: when isset($_post['search']) true , !empty($search) && $search != 'title:' false. in case $readnews parameter not initialized , statement not prepared, explains both errors.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -