bbram Posted October 18, 2012 Share Posted October 18, 2012 I have the following code $ifNameAlreadyExsist = "[0-9]"; //echo $newUserName[0-9]; echo $testUserName = $ifNewUserName[$ifNameAlreadyExsist]+; When I run the code I get the following error Parse error: syntax error, unexpected ';' in C:\wamp\www\new_signup.php on line if I have the following line of code $ifExsist = "SELECT COUNT( player_id ) FROM players WHERE player_id LIKE '$newUserName[0-9]'"; I get the following error: Parse error: syntax error, unexpected '-', expecting ']' in C:\wamp\www\new_signup.php on line 138 Can someone help me to figure out why I am getting the error messages listed above? Link to comment https://forums.phpfreaks.com/topic/269651-find-the-exact-match-plus-number/ Share on other sites More sharing options...
ManiacDan Posted October 18, 2012 Share Posted October 18, 2012 echo $testUserName = $ifNewUserName[$ifNameAlreadyExsist]+; Because PHP lines cannot end in a plus, the semicolon is unexpected. $ifExsist = "SELECT COUNT( player_id ) FROM players WHERE player_id LIKE '$newUserName[0-9]'"; This line is valid, perhaps there's lines above it which are causing issues. Link to comment https://forums.phpfreaks.com/topic/269651-find-the-exact-match-plus-number/#findComment-1386166 Share on other sites More sharing options...
kicken Posted October 18, 2012 Share Posted October 18, 2012 $ifExsist = "SELECT COUNT( player_id ) FROM players WHERE player_id LIKE '$newUserName[0-9]'"; The problem there is that PHP is trying to treat your $newUserName variable as an array and index into it, but it can't understand your index of 0-9. I personally have no idea what exactly you're trying to accomplish with said line. If $newUserName is an array, and you have a string index '0-9' you would use: $ifExsist = "SELECT COUNT( player_id ) FROM players WHERE player_id LIKE '{$newUserName['0-9']}'"; If $newUserName is not an array but just a string, and you want that string to be followed by the string '[0-9]', you'd use: $ifExsist = "SELECT COUNT( player_id ) FROM players WHERE player_id LIKE '{$newUserName}[0-9]'"; If neither of those is what you mean you'll have to explain what your end goal is. Link to comment https://forums.phpfreaks.com/topic/269651-find-the-exact-match-plus-number/#findComment-1386170 Share on other sites More sharing options...
ManiacDan Posted October 18, 2012 Share Posted October 18, 2012 Nice catch Kicken. Link to comment https://forums.phpfreaks.com/topic/269651-find-the-exact-match-plus-number/#findComment-1386178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.