Jump to content

Undefined Index


shackwm60

Recommended Posts

Please explain the philosophy here..

 

if this is ok and generates no errors or Notices

$result = mysqli_query($connection, $query);
 
if (!$result) {
   die("Database Query Failed: " . mysql_error());
 } else {
        }  

while ($row = mysqli_fetch_array($result)) {

echo "<tr>";
echo "<td>Address</td>";
echo "<td>";
echo $row['streetaddress'];
echo "</td></tr>";

}

Why does this code which is seemingly the same - aside from the logic test - generate an Undefined Index Notice?

if (!empty($row['child1name'])) {
echo "<tr>";
echo "<td colspan=\"2\">";
echo $row['child1name'] . " (" . $row['child1age'] . ")";
}


and is the correct answer to decalre all of these variables in advance?

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/293925-undefined-index/
Share on other sites

What is undefined? Perhaps 'child1age' doesn't exist in your $row. We know 'child1name' exists because you test for it, so 'child1age' is the only other thing there that could be causing an issue. Hard do know since you chopped off the code showing the actual query, and what you selected.

Link to comment
https://forums.phpfreaks.com/topic/293925-undefined-index/#findComment-1502955
Share on other sites

Usually it doesn't just say "undefined index". It says which index is undefined and which line it is occurring on. So exactly what does the notice say?

 

But again, my guess is that child1age isn't a field in the table you are querying, or isn't present in the result for some reason.

Link to comment
https://forums.phpfreaks.com/topic/293925-undefined-index/#findComment-1502963
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.