-2
$selected_id = -1;
$selected_name = "";
if(isset($_GET['cid'])){
    $cid = $_GET['cid'];
    $res = $pdo->prepare("SELECT * FROM k WHERE id = :cid");
    $res->bindParam(":cid",$cid);
    $result = $res->execute();

    $rw = $result->fetchAll([$cid]);
    if($rw){
        $selected_id = $rw['id'];
        $selected_name = $rw['ime'];
    }
}

I want to select only ID and compare with already selected ID but always is this error can anybody help me,please...

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Z.g
  • 1
  • 4

1 Answers1

1

$res->execute returns a boolean, which you save in the $result variable:

http://php.net/manual/en/pdostatement.execute.php

You are not using the same object, so you cannot use the object's fetchAll method. You should be using the same object, so you should be doing this instead:

$selected_id = -1;
$selected_name = "";
if(isset($_GET['cid'])){
    $cid = $_GET['cid'];
    $res = $pdo->prepare("SELECT * FROM k WHERE id = :cid");
    $res->bindParam(":cid",$cid);
    $res->execute(); // Run the method

    $rw = $res->fetchAll([$cid]); // Store the fetchAll result in a new variable
    if($rw){
        $selected_id = $rw['id'];
        $selected_name = $rw['ime'];
    }
}
Erik van de Ven
  • 4,747
  • 6
  • 38
  • 80