'PHP/Mysql receiving Undefined array key in foreach loop
I have a very simple php script that I am trying to run. It ran previously on another portion of my project and worked beautifully. I copied the snippet I needed to use for another section and even though the first previously run script still works the snippet copy refuses to work the same. I searched here for the last 2 days and while there are "similar" posts, I couldn't find anything that helped in my current predicament which is odd or I am just super special :) I'm new here and this is my first question so If I did something wrong with it, I apologize. I am just completely stumped as to how/why it's happening when it works perfectly in another spot. Any help is appreciated. If more information is needed just let me know.
TestCode.php
<?php
require_once("../data/config.php");
$stmt = $dbConnection->prepare("SELECT * from groupleaders");
$stmt->execute();
$results = $stmt->fetchALL(PDO::FETCH_ASSOC);
foreach($results as $row) {
//I tried making variables but it kept telling me Undefined array key
$name = $row['name'];
//after banging my head with the errors I commented all the variables out and did print_r($row); which returned everything as it should so I know the information is there.
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
