diff uk/index.php @ 19:84a412b8122c

try to protect against a range of missing info
author Charlie Root
date Thu, 30 Aug 2018 17:18:12 -0400
parents 7a532f1e0f07
children d606320ec331
line wrap: on
line diff
--- a/uk/index.php	Sun Jul 30 05:34:46 2017 -0400
+++ b/uk/index.php	Thu Aug 30 17:18:12 2018 -0400
@@ -140,8 +140,25 @@
 				{
 					$bookDetails = getAmazonDet($isbn,1,'uk'); 
 					$bookXML = new SimpleXMLElement($bookDetails);
-					$title = $bookXML->Items->Item[0]->ItemAttributes->Title;
-					$author = $bookXML->Items->Item[0]->ItemAttributes->Author;
+					if ($bookXML->Items && $bookXML->Items->Item[0] &&
+					    $bookXML->Items->Item[0]->ItemAttributes)
+					  { $attrs=$bookXML->Items->Item[0]->ItemAttributes;
+					    if ($attrs->Title) {
+					      $title = $attrs->Title; }
+					    else {
+					      $title ="[no Title]";
+					    }
+					    if ($attrs->Author) {
+					      $author = $attrs->Author;
+					    }
+					    else {
+					      $author ="[no Author]";
+					    }
+					  }
+					else {
+					  $title ="[no Title]";
+					  $author = "[no Author]";
+					}
 				}
 
 				$linkedBooks = include "../php/read/getLinkedBooks.php"; 
@@ -166,8 +183,21 @@
 					{					
 						$bookLDetails = getAmazonDet($linkedISBN,1,'uk'); 
 						$bookLXML = new SimpleXMLElement($bookLDetails);
-						$titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title;
-						$authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author;
+						if ($bookLXML->Items &&
+						    $bookLXML->Items->Item[0] &&
+						    $bookLXML->Items->Item[0]->ItemAttributes) {
+						  $attrs=$bookLXML->Items->Item[0]->ItemAttributes;
+						  if ($attrs->Title) {
+						    $titleL = $attrs->Title; }
+						  else {
+						    $titleL = ""; }
+						  if ($attrs->Author) {
+						    $authorL = $attrs->Author; }
+						  else {
+						    $authorL = ""; }
+						}
+						else {
+						  $titleL = ""; }
 					}
 					if($titleL != "")
 					{