Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Slynge · Sep 16, 2011 at 08:40 AM · stringmysql

MySQL: Seperation with "," when concatenating two strings

Hi guys,

Have a little problem when using MySQL through unity. I am trying to receive a string from a (VARCHAR) table in MySQL, and when received, i want to combine it with another string. Each string should be separated by a "," so for example if I receive a "3" and want to add a "5", the result should be "3,5".

I connect through Unity to a .php script on my server which gets the existing string of the table, as seen in the GetUserProjectId(). Afterwards I call the AddToUserProjectId() which takes the existing string "userProjectIdString" and the new string "projectId.ToString()" and forwards them to another .php script.

 function GetUserProjectId(){
     var URL = "http://getsharp.net/getUserProjectId.php"; //change for your URL
     userId = userId+1;
     var form = new WWWForm(); //here you create a new form connection
     form.AddField( "myform_hash", hash ); //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file
     form.AddField( "myform_userId", userId );
     var w = WWW(URL, form); //here we create a var called 'w' and we sync with our URL and the form
     yield w; //we wait for the form to check the PHP file, so our game dont just hang
     if (w.error != null) {
         print(w.error); //if there is an error, tell us
     } else {
         formText = w.text; //here we return the data our PHP told us
         w.Dispose(); //clear our form in game
     }
     
     userProjectIdString = formText;
     
     AddToUserProjectId();
     
 }


 function AddToUserProjectId(){
     var URL = "http://getsharp.net/addToUserProjectId.php"; //change for your URL
     var form = new WWWForm(); //here you create a new form connection
     form.AddField( "myform_projectIdExisting", userProjectIdString );
     form.AddField( "myform_projectIdNew", projectId.ToString() );
     form.AddField( "myform_userId", userId );
     form.AddField( "myform_hash", hash ); //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file
     var w = WWW(URL, form); //here we create a var called 'w' and we sync with our URL and the form
     yield w; //we wait for the form to check the PHP file, so our game dont just hang
     if (w.error != null) {
         print(w.error); //if there is an error, tell us
     } else {
         formText = w.text; //here we return the data our PHP told us
         w.Dispose(); //clear our form in game
     }
     print(formText);
 }

There is no problem adding a "," between the two strings in my .php script called "addToUserProjectId.php", and updating the string to my table, but it is when I want to receive the existing string from "getUserProjectId.php" that the error occurs. The .php script automatically removes the "," and just gives me a string only with numbers. Below is the .php code that selects the existing string from the database.

 $userId = anti_injection_login($_POST["myform_userId"]);
 if ($unityHash != $phpHash){
         echo "HASH code is different from your game, you infidel.";
     } else {
         $sql = mysql_query("SELECT projectId FROM users WHERE id='$userId'");
         while($result = mysql_fetch_array($sql)) {
         $projectId = $result["projectId"];
         $data = $projectId;
         echo $data;
         }
 }

And just so I am sure that there is no error when updating the table, below is the code from the .php script where I update my table with the two strings:

 $projectIdExisting = anti_injection_login($_POST["myform_projectIdExisting"]); //I use that function to protect against SQL injection
 $projectIdNew = anti_injection_login($_POST["myform_projectIdNew"]);
 
 if($projectIdExisting == null){
     $idToInsert = $projectIdNew;
 }else{
     $idToInsert = $projectIdExisting.",".$projectIdNew;
 }
 
 $userId = anti_injection_login($_POST["myform_userId"]);
 
 if ($unityHash != $phpHash){
         echo "HASH code is different from your game, you infidel.";
     } else {
         
         $query = "UPDATE users SET projectId='$idToInsert' WHERE id='$userId'";
 
         mysql_query($query) or die ('Error updating database');
     
         echo"Database updated";
 }

Anybody see a problem?

Thanks.

Comment
Add comment · Show 1
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 japanitrat · Sep 16, 2011 at 09:19 AM 0
Share

Are you sure that the projectId is really saved with a comma in your mySQL? what kind of id is that, that is a string containing actually two id's?

I think this is not related to Unity and SQL questions are certainly better to be asked at stackoverflow

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Slynge · Sep 16, 2011 at 10:16 AM

Thanks for your reply. I figured out the problem actually. It was a function inside my .php script that replaced "," with nothing. Some of the errors that can occur when you haven't made the script yourself ;)

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Checking whether string is a valid Input.Key 1 Answer

Store data in MySQL DB 4 Answers

How can i split a string[] ? 1 Answer

Sending a string via email from Unity? 2 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