Hi everyone, The following code block is an extract from a controller file that I have: // Get list of site sections containing this item $sql = "SELECT siteSectionID FROM item_to_siteSection WHERE itemID='$itemID'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching list of selected site sections.'; include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $selectedSiteSections[] = $row['siteSectionID']; } // Build the list of all site sections $sql = "SELECT siteSectionID, siteSection FROM siteSections"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching list of site sections.'; include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $siteSections[] = array( 'siteSectionID' => $row['siteSectionID'], 'siteSection' => $row['siteSection'], 'selected' => in_array($row['siteSectionID'], $selectedSiteSections)); } PHP: The following is code in a related template file that outputs the above and allows the user to press an edit button in order to edit the contents of that record: <fieldset> <legend>Site Section:</legend> <?php foreach ($siteSections as $siteSection): ?> <div><label for="siteSection<?php htmlout($siteSection['siteSectionID']); ?>"><input type="checkbox" name="siteSections[]" id="siteSection<?php htmlout($siteSection['siteSectionID']); ?>" value="<?php htmlout($siteSection['siteSectionID']); ?>"<?php if ($siteSection['selected']) { echo ' checked="checked"'; } ?>/><?php htmlout($siteSection['siteSection']); ?></label></div> <?php endforeach; ?> </fieldset> <div> <input type="hidden" name="itemID" value="<?php htmlout($itemID); ?>"/> <input type="submit" value="<?php htmlout($button); ?>"/> </div> PHP: When I test this edit button, I get the following error: Notice: Undefined variable: selectedSiteSections in /Applications/MAMP/htdocs/new_site/admin/catalogue/items/index.php on line 471 Warning: in_array() [function.in-array]: Wrong datatype for second argument in /Applications/MAMP/htdocs/new_site/admin/catalogue/items/index.php on line 471 Line 471 is the following line: 'selected' => in_array($row['siteSectionID'], $selectedSiteSections)); PHP: I've been trying to troubleshoot for hours but can't see why it's saying 'selectedSiteSections' is an undefined variable. Can anyone see where the problem is? Appreciate any help.
For anyone else that had that error it comes from where a variable has not been set and you are trying to use it. You can remove notices in the error setting, I think it's error_reporting(E_ALL ^ E_NOTICE); PHP: That will report all errors and ignore the notices.