On Fri, Oct 25, 2013 at 8:27 PM, Stephen <stephe...@rogers.com> wrote:

> Problem Situation
>
> I have two web sites on the same shared host. They share code for the
> control panel. When executed for one site I get a warning (reproducible
> always), but on the other there is no warning.
>
> One my home server, set up in the same way, I do not get a warning for
> either site.
>
> The warning is from this code:
>
> if ( in_array( $keys, $photo_ids ) )
>
> *Warning*: in_array() expects parameter 2 to be array, null given in
> */home/rois3324/include/**cpprocessforms.php* on line *203*
>
> Steps
>
> 1) Photos are transferred to incoming directory using ftp.
> 2) Photo data is imported into database and files moved to web site's file
> system
> 3) Photos are linked to a "category" by
>     i) Specifying photos to consider by entering filespec using wildcards
>     ii) User presented with photos
>     iii) User selects photos to be added to category and clicks process
> button
>     iv) Form returns array of photo_ids (key in database table)
>     v) Form processor creates entry in "link" table that links category_id
> to photo_id
>     vi) A check is made to detect and reject when the link already exists
>
> This is where the error occurs
>
> I have looked at the code, but I am at a total loss to figure out why I
> have trouble on one site and not the other, even though they are using the
> code. And my home development system has no problems.
>
> I can't play trial and error on the development system.
>
> Anyone have any ideas?
>
> This is the code where the warning is triggered:
>
> function linkphotos( $dbh, $x ) {
>
>   global $thumbsdirectory;
>
>   $ret_str = "";
>   $cat_id = $x['category'];
>   $photos = $x['list'];
>   $sql0 = "SELECT photo_filename FROM photographs WHERE photo_id = :id";
>   $sql1 = "SELECT photo_id FROM gallery_photos WHERE photo_category = :id";
>   $sql2= "INSERT INTO gallery_photos VALUES ( :id, :photo_id, :order )";
>
>   $stmt = $dbh->prepare($sql0);
>   try {
>       foreach( $photos as $keys=> $on) {
>       $stmt->bindValue(':id', $keys);
>       $stmt->execute();
>       $row = $stmt->fetch(PDO::FETCH_ASSOC)**;
>       $filenames[$keys] = $thumbsdirectory . "/" . $row['photo_filename'];
>      }
>   } catch (PDOException $e) {
>     return 'Error selecting existing file names: ' . $e->getMessage();
>   }
>
>   $stmt = $dbh->prepare($sql1);
>   try {
>       $stmt->bindValue(':id', $cat_id);
>       $stmt->execute();
>       while ( list( $id ) = $stmt->fetch(PDO::FETCH_NUM)) {
>         $photo_ids[] = $id;
>       }
>     } catch (PDOException $e) {
>     return 'Error selecting existing photos: ' . $e->getMessage();
>   }
>
>   $stmt = $dbh->prepare($sql2);
>   try {
>       $stmt->bindValue(':id', $cat_id);
>       foreach( $photos as $keys=> $on) {
>         $ret_str .=  htmlimage($filenames[$keys], $filenames[$keys] ) .
> "<br />";
>         if ( in_array( $keys, $photo_ids ) ) { <<<<<<<<warning raised here
>             $ret_str .= "  Duplicate. Already in Category.<br />";
>         } else {
>           $stmt->bindValue(':photo_id', $keys);
>           $stmt->bindValue(':order', $keys);
>           $stmt->execute();
>           $ret_str .= "  Added to Category.<br />";
>         }
>       }
>   } catch (PDOException $e) {
>     return 'Error inserting new photos: ' . $e->getMessage();
>   }
>
>   return $ret_str;
> }
>
> --
> Stephen
>
>
Your $photo_ids array is not declared. After
$photos = $x['list'];
add
$photo_ids = array();

Reply via email to