From: "David Stoltz" on 25 Aug 2009 14:00 $rs->Fields(22) equals a NULL in the database My Code: if(empty($rs->Fields(22))){ $q4 = ""; }else{ $q4 = $rs->Fields(22); } Produces this error: Fatal error: Can't use method return value in write context in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32 Line 32 is the "if" line... If I switch the code to (using is_null): if(is_null($rs->Fields(22))){ $q4 = ""; }else{ $q4 = $rs->Fields(22); } It produces this error: Catchable fatal error: Object of class variant could not be converted to string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196 Line 196 is: <?php echo $q4;?> What am I doing wrong? Thanks!
From: Bastien Koert on 25 Aug 2009 14:17 On Tue, Aug 25, 2009 at 2:00 PM, David Stoltz<Dstoltz(a)shh.org> wrote: > $rs->Fields(22) equals a NULL in the database > > My Code: > > if(empty($rs->Fields(22))){ > $q4 = ""; > }else{ > $q4 = $rs->Fields(22); > } > > Produces this error: > Fatal error: Can't use method return value in write context in > D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32 > > Line 32 is the "if" line... > > If I switch the code to (using is_null): > if(is_null($rs->Fields(22))){ > $q4 = ""; > }else{ > $q4 = $rs->Fields(22); > } > > It produces this error: > Catchable fatal error: Object of class variant could not be converted to > string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196 > > Line 196 is: <?php echo $q4;?> > > What am I doing wrong? > > Thanks! > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > $q4 = '' . $rs->Fields(22); Note that it's two single quotes -- Bastien Cat, the other other white meat
From: "David Stoltz" on 25 Aug 2009 14:47 if(empty($rs->Fields(22))){ $q4 = ''; }else{ $q4 = ''.$rs->Fields(22); } Still produces errors, whether using "empty" or "is_null"....with single quotes.... ??? -----Original Message----- From: Bastien Koert [mailto:phpster(a)gmail.com] Sent: Tuesday, August 25, 2009 2:17 PM To: David Stoltz Cc: php-general(a)lists.php.net Subject: Re: [PHP] How to output a NULL field? On Tue, Aug 25, 2009 at 2:00 PM, David Stoltz<Dstoltz(a)shh.org> wrote: > $rs->Fields(22) equals a NULL in the database > > My Code: > > if(empty($rs->Fields(22))){ > $q4 = ""; > }else{ > $q4 = $rs->Fields(22); > } > > Produces this error: > Fatal error: Can't use method return value in write context in > D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32 > > Line 32 is the "if" line... > > If I switch the code to (using is_null): > if(is_null($rs->Fields(22))){ > $q4 = ""; > }else{ > $q4 = $rs->Fields(22); > } > > It produces this error: > Catchable fatal error: Object of class variant could not be converted to > string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196 > > Line 196 is: <?php echo $q4;?> > > What am I doing wrong? > > Thanks! > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > $q4 = '' . $rs->Fields(22); Note that it's two single quotes -- Bastien Cat, the other other white meat
From: Lars Torben Wilson on 25 Aug 2009 15:00 2009/8/25 David Stoltz <Dstoltz(a)shh.org>: > if(empty($rs->Fields(22))){ Hi David, You cannot call empty() on a function or class method like that. From the manual: Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). - http://www.php.net/empty You should assign the result of $rs->Fields(22) to a variable before calling empty() on it, or use a class variable access to check it, or check it first within the class and have Fields() return a suitable value if needed. Regards, Torben > $q4 = ''; > }else{ > $q4 = ''.$rs->Fields(22); > } > > Still produces errors, whether using "empty" or "is_null"....with single quotes.... > > ??? > > -----Original Message----- > From: Bastien Koert [mailto:phpster(a)gmail.com] > Sent: Tuesday, August 25, 2009 2:17 PM > To: David Stoltz > Cc: php-general(a)lists.php.net > Subject: Re: [PHP] How to output a NULL field? > > On Tue, Aug 25, 2009 at 2:00 PM, David Stoltz<Dstoltz(a)shh.org> wrote: >> $rs->Fields(22) equals a NULL in the database >> >> My Code: >> >> if(empty($rs->Fields(22))){ >> $q4 = ""; >> }else{ >> $q4 = $rs->Fields(22); >> } >> >> Produces this error: >> Fatal error: Can't use method return value in write context in >> D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32 >> >> Line 32 is the "if" line... >> >> If I switch the code to (using is_null): >> if(is_null($rs->Fields(22))){ >> $q4 = ""; >> }else{ >> $q4 = $rs->Fields(22); >> } >> >> It produces this error: >> Catchable fatal error: Object of class variant could not be converted to >> string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196 >> >> Line 196 is: <?php echo $q4;?> >> >> What am I doing wrong? >> >> Thanks! >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > $q4 = '' . $rs->Fields(22); > > Note that it's two single quotes > -- > > Bastien > > Cat, the other other white meat > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
From: Shawn McKenzie on 25 Aug 2009 15:22 David Stoltz wrote: > $rs->Fields(22) equals a NULL in the database > > My Code: > > if(empty($rs->Fields(22))){ > $q4 = ""; > }else{ > $q4 = $rs->Fields(22); > } > > Produces this error: > Fatal error: Can't use method return value in write context in > D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32 > > Line 32 is the "if" line... > > If I switch the code to (using is_null): > if(is_null($rs->Fields(22))){ > $q4 = ""; > }else{ > $q4 = $rs->Fields(22); > } > > It produces this error: > Catchable fatal error: Object of class variant could not be converted to > string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196 > > Line 196 is: <?php echo $q4;?> > > What am I doing wrong? > > Thanks! First off, if the value is NULL in the database then in PHP it will be the string "NULL" and not a null value as far as I remember. Second, you cant use a function/method in empty(). Thirdly, the string "NULL" is not empty. I'm not sure what DB class you're using here or what the Fields() method actually returns. You should do a var_dump($rs->Fields(22)) to see. If it returns a string (especially "NULL"), then this or some variation should work: $q4 = $rs->Fields(22); if($q4 == "NULL"){ $q4 = ""; } If it returns an empty string or false then you may have nothing to do. -- Thanks! -Shawn http://www.spidean.com
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: security question of ZCE exam Next: parse_ini_file problem [SOLVED] |