niche Posted March 22, 2010 Report Share Posted March 22, 2010 I get "Fatal error: Function name must be a string in" from this script: if (strlen($row2('firstname') > 0) { $hit = 1; } Where $row2('firstname') is a null value because it's from a query that produces zero records.How should I script my if statement to avoid the fatal error when zero records are selected?Thanks,Niche Link to comment Share on other sites More sharing options...
jeffman Posted March 22, 2010 Report Share Posted March 22, 2010 (edited) First, use [brackets] to access array values.You should already have safeguards that prevent you from assigning values to an array if your query produces no results. Test the return value of your query for false, and then (if it's true) pass it to mysql_num_rows before you do anything else. (I'm assuming you're using mysql.)Aside from that, the way to test an array value before you try to access it is with isset() or empty(), as in:if (isset($row2['firstname'] ) ) {// do something} Edited March 22, 2010 by Deirdre's Dad Link to comment Share on other sites More sharing options...
niche Posted March 22, 2010 Author Report Share Posted March 22, 2010 Please explain "use [brackets] to access array values".Thanks Link to comment Share on other sites More sharing options...
thescientist Posted March 22, 2010 Report Share Posted March 22, 2010 Aside from that, the way to test an array value before you try to access it is with isset() or empty(), as in:if (isset($row2['firstname'] ) ) {// do something} Link to comment Share on other sites More sharing options...
jeffman Posted March 22, 2010 Report Share Posted March 22, 2010 (edited) $row2['firstname']instead of$row2('firstname') Edited March 22, 2010 by Deirdre's Dad Link to comment Share on other sites More sharing options...
niche Posted March 22, 2010 Author Report Share Posted March 22, 2010 So, I don't have to use PHP Sessions to use isset()? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 22, 2010 Report Share Posted March 22, 2010 The isset function doesn't have anything to do with sessions. Isset only checks if a variable is set, nothing more, nothing less. Link to comment Share on other sites More sharing options...
niche Posted March 22, 2010 Author Report Share Posted March 22, 2010 Why doesn't isset() show up under any of the PHP Reference lists? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 22, 2010 Report Share Posted March 22, 2010 Because the lists aren't complete.http://www.php.net/manual/en/function.isset.php Link to comment Share on other sites More sharing options...
niche Posted March 22, 2010 Author Report Share Posted March 22, 2010 I didn't know that!Point well taken - " don't be satisfied with the easily digested "how to" guides and online documentation - it's shallow."Justsomeguy's last thread allowed me to answer what was to be my next question by finding is_null().Thanks to Deirdre's Dad, thescientist, and justsomeguy. I'm very grateful for your help.Niche Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now