Notice: Use of undefined constant ResultSet - assumed 'ResultSet' http://www.toseef.com/img.php I'm trying to use the Y! Image API, although it returns the correct results at the bottom I'm getting the error stated above and don't know why
those arent actually errors, they are just notices. turn off notice reporting in php.ini or // Report all errors except E_NOTICE // This is the default value set in php.ini error_reporting(E_ALL ^ E_NOTICE); PHP: http://us3.php.net/error_reporting
Notices are errors, theyare just smaller class errors. Turning off notices in any script is not a very good solution, you should just fix the script instead. For example, this notice notified you that you were using an un-initialised variable in your script, which can be potentially dangerous.
Edmunds you got a point. Thing is I'm clueless why I'm getting the errors,ca n anyone help? Script is at http://www.toseef.com/img.php and the code is here http://www.toseef.com/img.txt
I'm bangin my head against a wall here, can anyone help? Simple solution is to turn off error_reporting but I dont really wanna go down that route ...
Are they variables or just constants? If they are variables, then use $ before the var name. Have you defined them anywhere before this line?
They aren't constants, they are array element names. HUGE difference. If you are writing something like this: $var[name] Then you are wanting to find the array element , which has the same value as the constant "name". As in define('name', 'blahblah'); echo $var[name]; Code (markup): is the same as echo $var['blahblah'] Code (markup): If you wish to find, just the element of the array called "name", do $var['name'] (notice the apostrophes!) Code (markup): So, the correct of the above would be $title = $phpobj['ResultSet']['Result'][$i]['Title']; Code (markup):
Nice one Edmunds, that really helped and I've managed to reduce the bulk of the errors. Only errors now are along the lines of Notice: Undefined index: q in httpdocs/web on line 40 I think this is something to do with the script needing php5 when my server is using php4, so I will most likely surpress the errors.
If you look at http://www.dasna.com/web you'll notice it says Notice: Undefined index: q in /sites/dasna.com/htdocs/web on line 40 and on line 40 I have $q = $_GET["q"]; PHP: Whats the deal here?
you need to check if its available first: $q = somedefaultvalue; if ( isset($_GET["q"]) ){ # TODO validate q, prevent hacks $q = $_GET["q"]; } PHP:
It happened because 'q' and 'p' are undefined. You need to define these varaibles before using them in your script. This will work. Replace the line 40 with the below if(!isset($_GET['q'])) $q = ''; else $q = $_GET['q']; if(!isset($_GET['p'])) $p = 1; else $p = $_GET['p']; hope it helps. edit: to add the else part
I find this syntax to be the easiest: if (!isset($_GET['q'])) $_GET['q'] = FALSE; $q = $_GET['q']; PHP: This is supposedly bad practice because you're not supposed to write to superglobal variables, but I honestly don't care.
I think I need to read a PHP book to understand this stuff, thanks for the input guys. I'll be using isset more often thats for sure!