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 /
avatar image
1
Question by sephiroth111 · Mar 18, 2012 at 11:40 AM · c#mysqltextarea

Unity3d C# select statement for GUI.TextArea

Good day to all, i have a problem, i have made a login with mysql remote connection. when im trying to login i cant login. i dont know how to use the GUI.TextArea exactly. here is my code:

 void OnGUI()
 {
 GUI.Box(new Rect(Screen.width/2-60,Screen.height/2-105,120,210),"Score");
 firstName = GUI.TextArea(new Rect(Screen.width/2-45,Screen.height/2-80,90,20),firstName);
 Password = GUI.TextArea(new Rect(Screen.width/2-45,Screen.height/2-50,90,20),Password);
 if(GUI.Button(new Rect(Screen.width/2-45,Screen.height/2-20,90,20),"Continue"))

 {
     SelectDatabase(firstName,Password);
 }
 if(GUI.Button(new Rect(Screen.width/2-50,Screen.height/2+70,100,20),"Back to Menu"))
 {
     Application.LoadLevel("mainMenu");
 }
 }
 public void SelectDatabase(string username, string password)
 {
 connectionstring = @"Server=db4free.net; Port=3306; Database=gladia***; Uid=der****; Password=*********;";
 conn = new MySqlConnection(connectionstring);
 da = new MySqlDataAdapter();
 ds = new DataSet();
 try 
 {
     da.SelectCommand = conn.CreateCommand();
     da.SelectCommand.CommandText = "select * from users where username=@username and password=@password";
     da.SelectCommand.CommandType = CommandType.Text;
     da.SelectCommand.Parameters.Add("@username",MySqlDbType.Text,15,"username").Value = username;
     da.SelectCommand.Parameters.Add("@password",MySqlDbType.Text,15,"password").Value = password;
     da.Fill(ds,"users");
     if (ds.Tables["users"].Rows.Count == 1) 
     {
         Debug.Log("pasok!");
     }
     else 
     {
         Debug.Log("Wrong username and Password");
     }
 } 
 catch (System.Exception ex) 
 {
     Debug.Log(ex.Message);
 }
 }

if i change the @username to a correct username and @password to correct password im successfully login. what may be the possible reason why Debug.Log("Wrong username and Password"); always prompting? i think the problem is in firstName and Password variables but i dont know how to fix it. thank you in advance.

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Mar 18, 2012 at 11:52 AM

I never used the Parameters collection. Usually i just build the sql command "manually" like this:

 da.SelectCommand.CommandText = "select * from users where username='" + username + "' and password='" + password + "'";

Beside that, keep in mind that a TextArea allows newline characters. You might want to use a TextField instead.

That might fix your problem, but your database setup is not very safe!!!
The C# code of your game can easily be viewed with a C# reflector, even from a web build. Never open a direct database connection from a user's PC. You usually use a server side script (like a PHP script) on a webserver to handle database interactions.

Comment
Add comment · Show 4 · 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 sephiroth111 · Mar 18, 2012 at 12:59 PM 0
Share

Thank you for that code. but still im searching for a way to use the parameter collection.

avatar image Bunny83 · Mar 18, 2012 at 04:33 PM 0
Share

Well if you need / want to use it, you might better use the 3 parameter version ins$$anonymous$$d of the 4 parameter version. I'm not quite sure to what "source column" is referring to, but since it's just a parameter replacement in your query there is no source column. You feed the data external. I guess you might need a source column for subqueries or something like that.

Also do you need the type $$anonymous$$ySqlDbType.Text? Usually you would use $$anonymous$$ySqlDbType.NVarChar.

avatar image sephiroth111 · Mar 19, 2012 at 02:03 AM 0
Share

SqlDbType wont work, that's why im using $$anonymous$$ySqlDbType. still not working. i found the problem but i dont know how to fix it. the problem is not the textarea(i already changed it to textfield) but the

da.SelectCommand.Parameters.Add("@username",$$anonymous$$ySqlDbType.Text,15,"username").Value = username; da.SelectCommand.Parameters.Add("@password",$$anonymous$$ySqlDbType.Text,15,"password").Value = password;

i dont know why this is wrong but this is my way of coding even when im creating a simple software the involves local and remote database

avatar image sephiroth111 · Mar 19, 2012 at 09:05 AM 0
Share

i found the solution, ins$$anonymous$$d of using @ i replaced ?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Problem in starting mysqld Process 0 Answers

MySql Online Character About 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Trigger player movement on touch 1 Answer


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