Need some MySQLi help x.x @ultrilliam
I'm having an error: `Parse error: syntax error, unexpected token "else" in [directory to]\functions.inc.php on line 19` When my code is as follows: (Lines 14-23) ``` 14 function invalidUid($username) { 15 $result; 16 if (!preg_match("/^[a-zA-Z0-9]*$/", $username) { 17 $result = true 18 } 19 else { 20 $result = false; 21 } 22 return $result 23 } ```
This is PHP help, not so much MySQLi, your problem is in line 16, you don't have the closing parenthesis to the if statement, only to the function.
You're also missing the semicolon at the end of line 22 and 17
I see now, thanks
Also your spacing is also wonky, though that's less important: ```php function invalidUid($username) { $result; if (!preg_match("/^[a-zA-Z0-9]*$/", $username)) { $result = true; } else { $result = false; } return $result; } ``` I'm also not entirely sure why you just have $result on line 15, it's not defining it without an `=` sign
It’s a placeholder to define it
It doesn't get defined like that, in fact I'm fairly sure that will throw a compiler warning about the variable not being defined but being called. Since you have an if/else here, there really isn't a need to define it, but if you wanted to, you would have to do `$result = false;` as a temporary assign. PHP doesn't really have a way to declare a variable before use, unlike JavaScript
Join our real-time social learning platform and learn together with your friends!