Beauford Posted July 9, 2008 Share Posted July 9, 2008 Hi, I always seem to have a problem with null or no values in a string, if someone could enlighten me on why the following work and/or don't work it would be appreciated. In the following example $formerror['lastname'] has a value regardless if there is an error or not. If I echo it there is nothing there, but if I do a count it shows as 1. $formerror[firstname'] = ValidateString($firstname); This on the other hand works fine. if($firstname) { $result = ValidateString($firstname); $formerror['firstname'] = $result; } This is the function: function ValidateString($stringvalue) { if(!preg_match("/[-A-Za-z0-9_&'.:,\\\()\" ]+$/", $stringvalue)) { return invalidchars; } } So my source of confusion is this, if there is no error, nothing is being returned from the function, so how can $formerror['firstname'] in the first example have a value, and why doesn't $result from the second example not get this phantom value, and lastly - who's on first? This is just one of these things I just can't seem to get my head around. Thanks Link to comment https://forums.phpfreaks.com/topic/113993-form-validation-and-functions/ Share on other sites More sharing options...
discomatt Posted July 9, 2008 Share Posted July 9, 2008 $formerror[firstname'] Should be $formerror['firstname'] Try error_reporting(E_ALL) Link to comment https://forums.phpfreaks.com/topic/113993-form-validation-and-functions/#findComment-585855 Share on other sites More sharing options...
Beauford Posted July 9, 2008 Author Share Posted July 9, 2008 $formerror[firstname'] simply a typo when posting this message. Since I am assuming both my examples are working as designed, what would be the purpose of error_reporting(E_ALL) as there is no error. Thx Link to comment https://forums.phpfreaks.com/topic/113993-form-validation-and-functions/#findComment-585875 Share on other sites More sharing options...
discomatt Posted July 9, 2008 Share Posted July 9, 2008 Because you may be suppressing any errors that could potentially be displayed. Notices also help with the debugging process, and they're disabled in most cases Link to comment https://forums.phpfreaks.com/topic/113993-form-validation-and-functions/#findComment-585883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.