0

i am getting PHP Notice: Undefined index error in my site.

PHP Notice: Undefined index: title in /home/kashan/public_html/ifunnygag.com/templates/wlol_v1/pages/header.php on line 41 [15-Apr-2013 06:36:42] PHP Notice: Undefined index: url in /home/kashan/public_html/ifunnygag.com/templates/wlol_v1/pages/header.php on line 42

var opts = {
Line 40 message : '<?php echo $file['title'];?>',
Line 41 name : '<?php echo $file['title'];?>',
Line 42 link : '<?php echo $file['url'];?>',
    description : 'Click to see pic...',
Line 44 picture : '<?php echo $file['path'];?>'

};

FB.api('/me/feed', 'post', opts, function(response)
{
    if (!response || response.error)
    {
        console.log(response);
    }
    else
    {
        console.log('Success - Post ID: ' + response.id);
    }
});

}

John Conde
  • 217,595
  • 99
  • 455
  • 496
Charming Guy
  • 3
  • 1
  • 2

4 Answers4

1

If you want to leave the values empty if they are not set then use like

<?php echo isset($file['title'])?$file['title']:"";?>
Jibran K
  • 885
  • 7
  • 20
0

First of all check your $file array should have those indexes which u trying to echo, if it is there then do like this

"<?php echo $file['title'];?>"
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
0

You can check variables and array indexes using isset() or empty() before using them. I.e.

if (empty($file['url'])) {
 $file['url'] = '';
}

But you may also want to make sure that it isn't empty due to some other serious problem. I.e. Post fields that are not validated properly before being accepted. If a required post field is empty, you might want to reject the post request entirely.

0

Check if the quotes are causing the problem. Try,

"<?php echo $file['title'];?>"
Sid
  • 854
  • 9
  • 23