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

CiscoTavonAsked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
Well, the error is complaining about the line:

     $xml = new SimpleXMLElement($xml_request_url, null, true);


The constructor only expects one parameter, but you are currently passing it 3.
0
 
Minh Võ CôngCommented:
Can you describe the problem more clearly?
0
 
CiscoTavonAuthor Commented:
I don't understand.  what should it say to get it to work?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Carl TawnSystems and Integration DeveloperCommented:
What version of PHP are you using?
0
 
CiscoTavonAuthor Commented:
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

0
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
Ah, that will be your problem then. Apparently SimpleXML requires PHP v5.1.2 or above.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.