Jump to content

PHP Code Unexpectedly Ending


HardlyWorking

Recommended Posts

I'm writing a PHP code to read an xml document from an external location. But whenever the character '>' appears in my code, the page takes it as the end of the <?php tag and doesn't read the rest of the code, and prints it as text on the page instead. I've used this syntax to get xml variables before without this problem. Any ideas?

 

Code: $xml = simplexml_load_file('books.xml') or die ("no file loaded");

  $xml2 = simplexml_load_file($completeurl2) or die ("no file loaded2");

 

    $smallisbn = $xml->(code is breaking here)ItemSearchResponse->Items->Item->ItemAttributes->ISBN;

$title = addslashes($xml->ItemSearchResponse->Items->Item->ItemAttributes->Title);

$titleLong = addslashes($xml2->BookList[0]->BookData[0]->TitleLong);

$author = addslashes($xml2->BookList[0]->BookData[0]->AuthorsText);

$publisher = addslashes($xml->ItemSearchResponse->Items->Item->ItemAttributes->Publisher). ", " . $xml->ItemSearchResponse->Items->Item->ItemAttributes->PublicationDate . ", " $xml->ItemSearchResponse->Items->Item->ItemAttributes->Edition . "edition";

 

Link to comment
https://forums.phpfreaks.com/topic/164107-php-code-unexpectedly-ending/
Share on other sites

Apparently this is a Firefox error, since when I switched to IE to run it, it worked fine. I'd still appreciate any light anyone can shed on the subject.

Neither Firefox nor IE execute PHP code.

 

Do a "view source" and see what the HTML being generated actually is.

I know, what I meant was that I was running it in the browser from the localhost server on my computer, which does run PHP.

 

Here's the source of the HTML page:

<html>

<head>

<title>Run to Load Database</title>

</head>

<body>

<?php

error_reporting(E_ERROR | E_WARNING | E_PARSE);

 

$DBConnect = mysqli_connect("localhost","user","pass");

if (!$DBConnect)

  {

  die('Could not connect: ' . mysqli_error());

  }

 

 

/*mysqli_query($DBConnect, "CREATE DATABASE library") or die("Unable to execute query: " . mysqli_error($DBConnect));*/

 

mysqli_select_db($DBConnect, "mytestda_library");

 

/*$query = "CREATE TABLE book (ISBN, smallISBN, Title VARCHAR(1000), Author VARCHAR(1000), Publisher VARCHAR(1000))";

mysqli_query($DBConnect, $query);*/

 

$query  = "SELECT ISBN FROM books WHERE smallISBN=0";

$result = mysqli_query($DBConnect, $query);

 

while($row = mysqli_fetch_array($result))

{

$isbn = $row['ISBN'];

    $completeurl = 

      "http://isbndb.com/api/books.xml?access_key=6GACLX6U&index1=isbn&value1=" .$isbn; 

  $xml = simplexml_load_file($completeurl) or die ("no file loaded");

   

$tracks = $xml->(starts printing text on the html page starting here)ISBNdb->BookList->BookData;

 

    $smallisbn = $xml->BookList[0]->BookData[0]['isbn'] ;

$title = addslashes($xml->BookList[0]->BookData[0]->Title);

$titleLong = addslashes($xml->BookList[0]->BookData[0]->TitleLong);

$author = addslashes($xml->BookList[0]->BookData[0]->AuthorsText);

$publisher = addslashes($xml->BookList[0]->BookData[0]->PublisherText);

$dewey = $xml->BookList[0]->BookData[0]->Details[0]['dewey_decimal_normalized'] ;

 

echo $isbn . " " . $smallisbn . " " . $title . " " . $author . " " . $publisher;

 

$query = "UPDATE book SET smallISBN=$smallisbn, Title='$title', Author='$author', Publisher='$publisher' WHERE ISBN=$isbn";

    mysqli_query($DBConnect, $query) or die("Unable to execute query: " . mysqli_error($DBConnect));

 

   

}

 

 

echo $completeurl;

mysqli_close($DBConnect);

 

?>

 

 

</body>

</html

Archived

This topic is now archived and is closed to further replies.

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