Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by yellowbedsheet · Oct 26, 2014 at 02:03 PM · javascriptdatabaseloginphpuser

Unityscript PHP Login problem

I have built a simple login system. I am using a php file to communicate with the database. The scenario I need is to do the login and if login is successful then load the mission. I am being able to login without a problem but for some reason unityscript is not evaluating/passing a simple condition. I have been trying to figure it out since two days. This is my snippet:

 function login(w : WWW) {
     
     yield w;
     if (w.error == null) {
         SendMessage("User", user);
         if (w.text === "Logged in.") {
             
             Debug.Log("Login Successful");
             Application.LoadLevel("PrincipalScene");
 
         } else {
             message += w.text;
             Debug.Log(w.text);
         }
     } else {
         message += "Error: " + w.error + "\n";
     }
 }

The problem is in the condition if (w.text === "Logged in."). It is not passing for some reason. My php snippet is like this:

     if ($count == 0) {
         echo ("User does not exist. \n");
     } else if (($count == 1) && ($pass == $row['password'])) {
         echo("Logged in.");
     } else {            
         echo("Password does not match. \n");    
     }

I would be grateful if anyone could help in this.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Graham-Dunnett ♦♦ · Oct 26, 2014 at 02:04 PM 0
Share

What doe the Debug.Log() at line 13 print?

avatar image yellowbedsheet · Oct 26, 2014 at 06:02 PM 0
Share

It prints "Logged in.". But I want to see "Login successful" and start of the scene but it does not enter that block.

avatar image Landern · Oct 26, 2014 at 06:07 PM 0
Share

Ah, don't use a triple equals, it should be a double == for comparison and single = for assignment. This isn't actually JavaScript unity is using.

avatar image yellowbedsheet · Oct 26, 2014 at 06:12 PM 0
Share

I have tried that also but it didn't work. It is really strange this problem. Thank you.

avatar image Landern · Oct 26, 2014 at 06:20 PM 0
Share

Perhaps there are hidden characters, equals checks for explicit characters, try contains.

 if (w.text.ToLower().Contains("logged in"))
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Oct 26, 2014 at 06:33 PM

w.text most likely contains some new line characters which you simply don't see. If you compare strings they have to match 100%.

Try this:

 // UnityScript
 // ...
 var result = w.text.Trim(" "[0], "\n"[0], "\r"[0], "\t"[0]);
 if (result == "Logged in.")
     // ...
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yellowbedsheet · Oct 26, 2014 at 06:38 PM 0
Share

YEP. This one also works. Thanks a lot.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make my Login System networkable? 0 Answers

Smart way of using servers and databases in unity 0 Answers

need unity to connect with online admin panel and view credits,login system etc 0 Answers

How to use php login Form [POST] with c# 1 Answer

Getting Value From Site 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges