php - Undefined index warning on PDO::fetchAll index -


i'm having awful time trying track down cause of since there many different potential causes "undefined index" warning.

notice: undefined offset: 0 in d:\xampp\htdocs\inc\php_main.php on line 71 

the line $singleresult = $result[0]; line 71. i'm positive $result[0] set, i've verified both print_r , isset check. missing something? i'm sort of hoping need sanity check here. :)

function execute ($sql, $bindingsarray) {     $pdostmt = $this->db->prepare($sql);     $pdostmt->execute($bindingsarray);     $result = $pdostmt->fetchall(pdo::fetch_assoc);     print_r($result);     if (isset($result[0]) && isset($result[1])); {         $singleresult = $result[0];         return $singleresult;     }     return $result; } 

your variable not set , don't notice because if line wrong:

if (isset($result[0]) && isset($result[1])); {                                            ^ problem     $singleresult = $result[0];     return $singleresult; } 

is same as:

if (isset($result[0]) && isset($result[1])) {  } $singleresult = $result[0]; return $singleresult; 

because of ; put after condition. remove , results should expect them be:

if (isset($result[0]) && isset($result[1])) { 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -