0

This is my PHP file performing an HTTP request:

    $token='Food2forkKey';  //food2fork
    foo2fork  private key
    $fooddetail=new Food($token,"json");

$pid=$_GET['first'];
//$search='https://community-food2fork.p.mashape.com/search?key='.$token.'&q='.$pid;   //Food2fork
$search='http://food2fork.com/api/search?key='.$token.'&q='.$pid;
//key
echo $search;
$json=$fooddetail->call_url($search);
//echo $details;
if(!$json){
echo 'Error: Could not retrieve products list.';
exit();
}
//var_dump(json_decode($json,TRUE));
$details=json_decode($json,TRUE);
//var_dump($details);
echo $details;  

$title = $details['title'];
//print_r $title;
$publisher =  $details['publisher'];
//print_r $publisher;
$image=$details['source_url'];
//print_r $image;
?>
<html>
<head>

</head>
<body>
    <table border="1">
        <tr>
            <td><?php print_r ($title); ?></td>
            <td><img src="<?php print_r($image); ?>"</td>
        </tr>
    </table>    
</body>
</html>

This is Html file 


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

</head>

<body>
<form  method="get" action="foodsearch.php">
<input type="text" name="Search" />
<input type="submit" value="Submit" id="sub" />
</form>

</body>
</html>

The script fails with an "undefine index" error message. What is the reason behind that?

I use food2fork API. The returned JSON has title and publisher keys, but when I try to display the values, the script logs the above-mentioned error message.

Ruslan Osmanov
  • 20,486
  • 7
  • 46
  • 60
Hacker
  • 160
  • 11

0 Answers0