Ask your own question, for FREE!
Computer Science 7 Online
Extrinix:

Need some MySQLi help x.x @ultrilliam

Extrinix:

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 } ```

Ultrilliam:

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.

Ultrilliam:

You're also missing the semicolon at the end of line 22 and 17

Extrinix:

I see now, thanks

Ultrilliam:

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

Extrinix:

It’s a placeholder to define it

Ultrilliam:

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!