Link to home
Start Free TrialLog in
Avatar of CiscoTavon
CiscoTavon

asked on

How do i fix this Fatal error: Uncaught exception 'Exception'

How do i fix this Fatal error: Uncaught exception 'Exception' it was working but i must have changed something now it comes up with

Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects exactly 1 parameter, 3 given' in /home/07009321/public_html/f1.php:23 Stack trace: #0 /home/07009321/public_html/f1.php(23): SimpleXMLElement->__construct('http://www.allc...', NULL, true) #1 {main} thrown in /home/07009321/public_html/f1.php on line 23
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


  <head>
    <title>test</title>
  </head>
 
  <body>
        <form name='frmTest' method='post' action='<?php echo $_SERVER['PHP_SELF'];?>'>
              <input type='text' name='txtSearch'/>
              <input type='submit' value='Search'/>
        </form>
        
    <?php
   
      if (isset($_POST["txtSearch"])) {
        $user_name = 'UserName';
        $secret_key = 'gfjuhchj';
        $search_phrase = $_POST["txtSearch"];
        $query_hash = md5($secret_key.$search_phrase);
        $xml_request_url = 'http://www.allcdcovers.com/api/search/'.$user_name.'/'.$query_hash.'/'.urlencode($search_phrase);
        $xml = new SimpleXMLElement($xml_request_url, null, true);
        
        if (isset($xml->err)) {
          echo $xml->err['msg'];
        } else {
        print "<table>";
          foreach ($xml as $title) {
           echo  "<tr><td><h3>'Title: '</h3>".$title->name."</td></tr><br />";
            echo "<tr><h3>'Category: ''</h3>".$title->category.': '.$title->subcategory."<br />";
            echo "<a href='Image: '><img src=".$title->image."/></a> <br /> ";     
            
    
            foreach ($title->covers->cover as $cover) {
             
                       echo "<h3>'Average rating:''</h3>".$cover->average_rating."<br />";
                                        }
          }
        }
      }
    ?>
  </body>
</html>

Open in new window

Avatar of Cong Minh Vo
Cong Minh Vo
Flag of Viet Nam image

Can you describe the problem more clearly?
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CiscoTavon
CiscoTavon

ASKER

I don't understand.  what should it say to get it to work?
What version of PHP are you using?
version 5.0.4

I followed the websites example code.

I'm trying to get album art
1.
      <?php
   2.
      $user_name = 'lennon_22';
   3.
      $secret_key = 'BJz2LYhjOB4grzD8fhrt49rviSW3yvKTs';
   4.
      $search_phrase = 'beatles love';
   5.
      $query_hash = md5($secret_key.$search_phrase);
   6.
      $xml_request_url = 'http://www.allcdcovers.com/api/search/'.$user_name.'/'.$query_hash.'/'.urlencode($search_phrase);
   7.
      $xml = new SimpleXMLElement($xml_request_url, null, true);
   8.
      if (isset($xml->err)) {
   9.
        echo $xml->err['msg'];
  10.
      } else {
  11.
        foreach ($xml as $title) {
  12.
          echo 'Title: '.$title->name;
  13.
          echo 'Category: '.$title->category.': '.$title->subcategory;
  14.
          echo 'Image: '.$title->image;
  15.
          echo 'Image: '.$title->image;
  16.
          foreach ($title->covers->cover as $cover) {
  17.
            echo 'Cover type:'.$cover->type;
  18.
            echo 'Resolution:'.$cover->width.' '.$cover->height;
  19.
            echo 'Filesize:'.$cover->filesize;
  20.
            echo 'Upload date:'.$cover->uploaded_at;
  21.
            echo 'Average rating:'.$cover->average_rating;
  22.
            echo 'Download page:'.$cover->url;
  23.
            echo 'Thumbnail:'.$cover->thumbnail;
  24.
          }
  25.
        }
  26.
      }
  27.
      ?>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial