Jump to content

Find The Exact Match Plus Number


bbram

Recommended Posts

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

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.

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.