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 /
This question was closed Mar 31, 2017 at 08:46 AM by Bunny83 for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by MaxMekker · Mar 30, 2017 at 04:28 PM · databasephpsql

Getting Specific mySql Row by searching table with a name

Hi

I want to get specific data such as how long the user played the level and how much hp he has in the end of the level. And i want to get this info by using a name:

alt text

And through the name i want to get the whole row

Example:

Lets say i search using Max as a name. Then I whould want to get this row:alt text

Current Code PHP / MYSQL:

 <?php
  
  $servername = "localhost";
  $username = "mix";
  $password = "hellogai";
  $dbname ="mix";
  $tablename ="sidescroller";
   
  $name = $_POST['name'];
  
  $recivedHash = $_POST['hash'];
 
  // create conention to database
  $db = new mysqli ($servername, $username , $password, $dbname);
  
  //check connection
  
  if($db->connect_error){
      
      die("Connection Lost: " . $db->connect_error);
  }
 
  
  $sql = "SELECT Name, Time, Hp FROM " . $tablename . "WHERE Name = ". $name ;
  
   //Query the database
  $result = $db->query($sql); 
  
 
  
 //show if there is a result
 if($result->num_rows > 0)
 {
     //output data of each row
      $numbRow =0;
  
  while($row = $result->fetch_assoc())
  {
      echo $row['time'] . "-" . $row['hp'];
      
  }
 
  
 }
  
  $db->close();
  
   ?>
 


Current Unity Code:

     private string secretKey = "Maxil"; //password
     string UsernamesURL = "http://localhost/Highscore/Unity/usernames.php";
     string NameInfoURL = "http://localhost/Highscore/Unity/nameinfo.php";
     
     string Allnames;
     public List<string> IndividualUsers;
     string[] vectorUsers;
     string oldname;
     public Dropdown dropdownlist;
     public Text CurrentName;
     public Text NameInfoText;
     public static string PostingName;
     // Use this for initialization
     void Start () {
         StartCoroutine(GetNames());
         oldname = " ";
         PostingName = " ";
         
     }
     
     // Update is called once per frame
     void Update()
     {
         if (UserCreation.looper ==1)
         {
             StartCoroutine(GetNames());
            UserCreation.looper = 0;
         }
 
         if (oldname != PostingName)
         {
             StartCoroutine(Postname(PostingName)); //Postingname
             oldname = PostingName;
             StartCoroutine(GetNameInfo());
         }
         
 
 
 
     }
     public void Dropdown_index(int index)
     {
         CurrentName.text = IndividualUsers[index];
         PostingName = CurrentName.text;
     }
 
     IEnumerator Postname(string name)
     {
         string hash = Md5sum(name+ secretKey);
         //create form with the info connected to webpage POST
         WWWForm form = new WWWForm();
         form.AddField("name", name);
         form.AddField("hash", hash);
         //connect and send the form, to POST on webpage
         WWW www = new WWW(NameInfoURL, form);
         yield return www; //wait intill connection complete;
         if (www.error != null)
         {
             Debug.Log("Error: " + www.error);
         }
         else
         {
            NameInfoText.text = www.text;
         }
     }
     IEnumerator GetNameInfo()
     {
         WWW nameinfo_get = new WWW(NameInfoURL);
         yield return nameinfo_get;
         if (nameinfo_get.error != null)
         {
             Debug.Log("There was an error getting the score: " + nameinfo_get.error);
         }
         else
         {
 
             NameInfoText.text = nameinfo_get.text;
         }
     }
 
 
     IEnumerator GetNames()
     { //split string
         WWW names_get = new WWW(UsernamesURL);
         yield return names_get;
 
         if (names_get.error != null)
         {
             Debug.Log("There was an error getting the score: " + names_get.error);
         }
         else
         {
             Allnames = names_get.text;
             vectorUsers = Allnames.Split(',');
             IndividualUsers = new List<string>(vectorUsers);
             dropdownlist.ClearOptions();
             dropdownlist.AddOptions(IndividualUsers);
 
 
            
         }
 
     }
     public string Md5sum(string strToEncrypt)
     {
         System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
         byte[] bytes = ue.GetBytes(strToEncrypt);
 
         //encrypt
         System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
         byte[] hashBytes = md5.ComputeHash(bytes);
         string hashString = "";
         //convert to encrypted string
         for (int i = 0; i < hashBytes.Length; i++)
         {
             hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
         }
         return hashString.PadLeft(32, '0');
     }
 
 }
 



g.png (33.2 kB)
d.png (33.6 kB)
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 Bunny83 · Mar 31, 2017 at 08:45 AM 0
Share

I can't see any concrete question here. Your SQL query does already return that row for the given name (or any row that has that name). Too much code and no actual question asked. What's your actual problem?

Since the question is way to unspecific and not really about Unity I'm closing this question. If you know your actual question feel free to ask a new question. $$anonymous$$eep in $$anonymous$$d to only include necessary information and to describe your problem properly. For reference you could link this question in your new question.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using Unity to connect to a Database 3 Answers

php, sql security 3 Answers

how make player database 1 Answer

Is it possible to create GameObjects dinamically from a server? 1 Answer

simple online storage for game? Any other way? 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