If Statement Acting Strange

I’m trying to make a game in which you need to enter a code to get items you want. I have all the codes in a SQL table on my localhost and I’m using WWW and PHP to reach it. I’m also using String.Compare to compare a string received from the PHP script to a word or phrase. The errorMsg variable changes the value of a GUI Label which displays when the variable currentWindow is equal to Window.Failed. Here’s the function that controls that:

function RegisterItem(code : String) {
        registerURL = registerURL + "code=" + WWW.EscapeURL(code) + "&version=" + game.version;
     
        // Post the URL to the site and create a download object to get the result.
        var code_post = WWW(registerURL);
        currentWindow = Window.Downloading;
        yield code_post; // Wait until the download is done
        if(code_post.error) {
        	errorMsg = code_post.error;
            currentWindow = Window.NoConnection;
        } else {
        	if(String.Compare(code_post.text, "Used", true) > 0){
        		errorMsg = "It seems that this code has already been used...";
        		currentWindow = Window.Failed;
        		Debug.Log(code_post.text);
        	} else if(String.Compare(code_post.text, "No code", true) > 0){
        		errorMsg = "This code is not in our database.";
        		currentWindow = Window.Failed;
        		Debug.Log(code_post.text);
        	} else if(String.Compare(code_post.text, "Version", true) > 0){
        		errorMsg = "Download the latest version to register this item.";
        		currentWindow = Window.Failed;
        		Debug.Log(code_post.text);
        	} else if(PlayerPrefs.HasKey(code_post.text)) {
    			errorMsg = "It seems that you already own this item.";
        		currentWindow = Window.Failed;
        		Debug.Log(code_post.text);
        	} else {
        		game.item = code_post.text;
        		game.items.Push(game.item);
        		currentWindow = Window.CodeSuccess;
        	}
        }
    }

I have the Debug Log print out what the value of code_post.text is to see what it is. When I test run the game and use a fake code I entered into the SQL table, I see that in the Debug Log, it prints out “Version”, yet the GUI Label shows the phrase I put if code_post.text is equal to “Used”. It doesn’t seem to be a problem with the PHP script (although it shouldn’t be saying that the version is wrong, but I’m not focused on that right now). What could possibly be the problem?

Well, i just realized you used String.Compare which returns “an integer that indicates their relative position in the sort order”.

It should be 0 when they are equal since than they have the same “level” in the sort order.

You might want to use String.Equals instead and use the StringComparison value of CurrentCultureIgnoreCase for example.

if (code_post.text.Equals("No code", System.StringComparison.CurrentCultureIgnoreCase))

usually it’s simpler to just convert the string you want to test to lower-case and do an ordinary string comparison:

var code = code_post.text.ToLower();

if (code == "no code")
//[...]

Keep in mind that your “constants” need to be lower-case