Jump to content

Undefined Index


Go to solution Solved by 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.

Edited by CroNiX
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.