1

Okay so I have the following code:

    if ($AccountData ['nAuthID'] == 1 && $data['MAINT'] == True) {
    die ('MM');
}

That should technically work but for some reason it doesn't.

Basically in my text file I have said that maint is false but when it gets to this part of the code it still dies.

I think it's something to do with the '$data['MAINT'] == True' part but I am not sure what's wrong with it?

Here is all of the code:

$exec = mssql_query("SELECT nEMID, nAuthID, sUserPass FROM tAccounts where sUsername = '$user'");
$AccountData = mssql_fetch_assoc($exec);
$file = file('LauncherInfo.txt');

foreach ($file as $line) {
    if ($line) {
        $splitLine = explode(' = ',$line);
        $data[$splitLine[0]] = $splitLine[1];
    }
}

//echo $data['MAINT'];

if ($AccountData ['nAuthID'] == 2 && $data['MAINT'] == True) {
    //Continue.
} else if ($AccountData ['nAuthID'] == -2) {
    die ('INV');
} else if ($AccountData ['nAuthID'] == -1) {
    die ('BAN');
} else if ($AccountData ['nAuthID'] == 1 && $data['MAINT'] == True) {
    die ('MM');
} else if ($AccountData ['nAuthID'] == 0) {
    die ('EVR');
}

This is what is inside the text file 'LauncherInfo.txt':

IP = 127.0.0.1
EXE = Client.exe
PORT = 8080
TITLE = Title
MAINT = False
Maintenance-Message = The server is currently in maintenance.
Ban-Message = You have been banned sucker!
Email Verification-Message = You need to active your email adddress.
Investigation-Message = Your account is undergoing investigation.

EDIT:

I tried using the following codes:

if ($AccountData ['nAuthID'] == -2) {
    die ('INV');
} else if ($AccountData ['nAuthID'] == -1) {
    die ('BAN');
} else if ($AccountData ['nAuthID'] == 0) {
    die ('EVR');
} else if ($AccountData ['nAuthID'] == 1 && $data['MAINT'] == 'True') {
    die ('MM');
} else if ($AccountData ['nAuthID'] == 2 && $data['MAINT'] == 'True') {
    //Continue and allow user to log in.
}

I also tried this:

   if ($AccountData ['nAuthID'] == -2) {
        die ('INV');
    } else if ($AccountData ['nAuthID'] == -1) {
        die ('BAN');
    } else if ($AccountData ['nAuthID'] == 0) {
        die ('EVR');
    } else if ($AccountData ['nAuthID'] == 1 && $data['MAINT'] == "True") {
        die ('MM');
    } else if ($AccountData ['nAuthID'] == 2 && $data['MAINT'] == "True") {
        //Continue and allow user to log in.
    }

But neither of those work?

EDIT2: I changed my code to look like this:

    if ($AccountData ['nAuthID'] == -2) {
    echo ('INV');
} else if ($AccountData ['nAuthID'] == -1) {
    echo ('BAN');
} else if ($AccountData ['nAuthID'] == 0) {
    echo ('EVR');
} else if ($AccountData ['nAuthID'] == 1 && $data['MAINT'] == "True") {
    echo ('MM');
} else if ($AccountData ['nAuthID'] == 2 && $data['MAINT'] == "True") {
    //Continue and allow user to log in.
}

And what I see in the webbrowser is EVR. It seems like it doesn't even carry on from there?

Thanks.

6
  • That should technically work but for some reason it doesn't. Please tell us what it works is and what it currently is doing. Commented Jun 27, 2013 at 0:41
  • What would you like to know? The value is $data['MAINT'] is False when I echo it in the browser. The code first connects to the myssql database and then it executes a myssql command which returns a few values. Before I do anything with the values I scan the LauncherInfo.txt file to find out what MAINT is equal to and in this case it is equal to False so then it checks the value that it got from the database (nAuthID) and currently I have it set to 1 in the database so it should technically continue with the code because MAINT equals false but it still stops when it gets to AuthId = 1. Commented Jun 27, 2013 at 0:46
  • Note: if($var) is the same as if($var == true) Commented Jun 27, 2013 at 0:54
  • The code should technically be correct. No one knows what's wrong?$data['MAINT'] is a string because it's from a txt file correct? So I tried adding quotes (") around it but it didn't work. Commented Jun 27, 2013 at 1:06
  • Are you checking for the existence of MAINT in $data, or are you checking to see it MAINT is true? If the latter, you should be doing comparison of strings, and not bools. Commented Jun 27, 2013 at 1:06

2 Answers 2

2

You're checking if MAINT is True in the text file. You're essentially doing a comparison of strings. If you don't enclose it in quotes, PHP assumes it's a boolean (it's not). So you'll need to enclose it in double quotes like so:

if ($AccountData ['nAuthID'] == 2 && $data['MAINT'] == "True") {
} else if ($AccountData ['nAuthID'] == -2) {
    die ('INV');
} else if ($AccountData ['nAuthID'] == -1) {
    die ('BAN');
} else if ($AccountData ['nAuthID'] == 1 && $data['MAINT'] == "True") {
    die ('MM');
} else if ($AccountData ['nAuthID'] == 0) {
    die ('EVR');
}

Hope this helps.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried that but it didn't work. It should but it doesn't. This is confusing, I don't know why it's happening.
@FarbodD: What does $AccountData contain?
nEMID, nAuthID and sUserPass. If I change my AuthID in the myssql database to lets say -1 then it will output BAN.
1

file() leaves the newlines in the strings, so $data['Maint'] contains "True\n", not "True". You can use the FILE_IGNORE_NEW_LINES option to prevent this:

$file = file('LauncherInfo.txt', FILE_IGNORE_NEW_LINES);

Another option is to trim the line before processing it -- this will remove trailing spaces as well.

foreach ($file as $line) {
    $line = trim($line);
    if ($line) {
        $splitLine = explode(' = ',$line);
        $data[$splitLine[0]] = $splitLine[1];
    }
}

Then you also need to compare with "True", not True, as in Amal Murali's answer:

if ($AccountData ['nAuthID'] == 2 && $data['MAINT'] == "True") {

The other problem you're having is that you're getting an error from the SQL query, and not checking for it. After calling mssql_query(), do:

if (!$exec) {
    die('MSSQL error: ' . mssql_get_last_message());
}

This will show the error message from MSSQL.

20 Comments

Currently my code looks like this: puu.sh/3pc7w.png and the output in the browser looks like this: puu.sh/3pc8I.png
It prints EVR if $AccountData['nAuthID'] is 0. Your code checks that before checking $data['MAINT'], so none of these changes have any effect.
But $AccountData['nAuthID'] is 1 as we can see from here: puu.sh/3pcmD.png So because it is not 0 it should continue to the next else if statement?
What does var_dump($AccountData) show? Please edit it into your question as formatted text, not as a stupid link to an image.
Okay sorry, I thought that would be easier to understand. It says this: 'bool(false) EVR'
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.