diff de/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 077b0a0a3e6d
children a67bf725e87b
line wrap: on
line diff
--- a/de/index.php	Sun Jul 30 05:34:46 2017 -0400
+++ b/de/index.php	Thu Aug 30 17:18:12 2018 -0400
@@ -124,7 +124,7 @@
 				$ret = 1;
 				$countryCode = 3;
 				
-								include "../../private/db.php"; 
+				include "../../private/db.php"; 
 				$query = "CALL b_getBookInfo('$isbn', $countryCode)";
 				//echo $query;
 				$res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
@@ -138,10 +138,27 @@
 				}		
 				else
 				{
-					$bookDetails = getAmazonDet($isbn,1,'ca'); 
+					$bookDetails = getAmazonDet($isbn,1,'de'); 
 					$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,'de'); 
 						$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 != "")
 					{
@@ -273,7 +303,7 @@
 			FB.Canvas.setSize(obj);
 			</script>";
 		}
-	}
+	}	
 	?>
   
     <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>