|
-
Aug 9th, 2007, 04:31 PM
#1
Thread Starter
Member
[Resolved] Application not using switch for returned string from server
Alright, I have a program communicating with my server to login. The server sends back a success or failure code. The application gets the code, but doesn't use the switch/case I have set up in order to proceed.
Code:
string returnString = WebConnection.SendPostData("http://site.com/login.php", "username=" + strUsername + "&password=" + strPassword);
//MessageBox.Show(returnString);
switch (returnString)
{
case "1":
{
//Login success
MessageBox.Show("Login successful.");
//Insert Login code here
break;
}
case "2":
{
//Login failure
MessageBox.Show("Login failed.");
Application.Exit();
break;
}
}
If I enable the messagebox to display returnString, it properly shows me either 1 or 2, which it gets from the server. However, from there it doesn't display either of the messageboxes which show success or failure or execute the code it should be using. If I set one of the cases to default, it takes that regardless of the server's response. Is there something I'm missing with the way I'm using case to compare a string?
Last edited by Tural; Aug 9th, 2007 at 06:01 PM.
Reason: Resolved.
-
Aug 9th, 2007, 04:47 PM
#2
Re: Application not using switch for returned string from server
Are you absolutely positive that the returned string is just single character? There are no spaces or new lines hiding in there?
-
Aug 9th, 2007, 04:50 PM
#3
Thread Starter
Member
Re: Application not using switch for returned string from server
Yep.
PHP Code:
if($row['password'] == $password && $row['approved'] == 1)
{
echo "1";
}
else if($row['password'] != $password && $row['approved'] == 1)
{
echo "2";
}
-
Aug 9th, 2007, 05:50 PM
#4
Re: Application not using switch for returned string from server
 Originally Posted by Tural
Yep.
PHP Code:
if($row['password'] == $password && $row['approved'] == 1)
{
echo "1";
}
else if($row['password'] != $password && $row['approved'] == 1)
{
echo "2";
}
That wouldn't assure me; particularly since there is nothing wrong with your switch. Notice that if you pass it a correct string, it works just fine.
c# Code:
string returnString = "1";
switch (returnString)
{
case "1":
{
//Login success
MessageBox.Show("Login successful.");
//Insert Login code here
break;
}
case "2":
{
//Login failure
MessageBox.Show("Login failed.");
Application.Exit();
break;
}
}
Actually step through your code and see the value of returnString. It's not what you think it is.
-
Aug 9th, 2007, 05:57 PM
#5
Thread Starter
Member
Re: Application not using switch for returned string from server
After further messing with it, I see it is indeed returning the value with a line break at the end. I'll throw a substring in there to get rid of it. Thanks for the help.
Last edited by Tural; Aug 9th, 2007 at 06:01 PM.
-
Aug 9th, 2007, 06:02 PM
#6
Re: Application not using switch for returned string from server
You bet.
I don't know anything about PHP, but if you are going to use the return value like this why not just return a boolean or integer instead of messing around with a string?
Also, if you're done with this question, then you can mark the thread as Resolved.
Good luck.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|