hello i need update my script login and register and profile load data from my web site pls help me i need load data from name player....
Here is script on load profile data in my web site pls help me load data with name no MyID Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Runtime.Serialization.Formatters.Binary; using System.IO; using System; using UnityEngine.UI; public class Profile2 : MonoBehaviour { public string[] items; public string ID; public static string Name; public string State; public string Sex; public string Age; public int MyId; private PhotonView photonView; public GameObject ThisPlayer; public GameObject myPlayerName; public int viewID; void Awake() { photonView = this.gameObject.GetComponent<PhotonView>(); MyId = PlayerPrefs.GetInt("MyID"); viewID = photonView.viewID; StartCoroutine(LoadProfile()); if (photonView.isMine) { photonView.RPC("LoadID", PhotonTargets.AllBuffered , this.viewID, this.MyId ); this.viewID = viewID; this.MyId = MyId; } } IEnumerator LoadProfile() { WWW itemsData = new WWW("myWeb.php"); yield return itemsData; string itemsDataString = itemsData.text; print(itemsDataString); items = itemsDataString.Split(';'); ID = (GetDataValue(items[MyId], "ID:")); Name = (GetDataValue(items[MyId], "Name:")); State = (GetDataValue(items[MyId], "State:")); Sex = (GetDataValue(items[MyId], "Sex:")); Age = (GetDataValue(items[MyId], "Age:")); this.gameObject.name = Name; this.myPlayerName.GetComponent<TextMesh>().text = Name; } string GetDataValue(string data, string index) { string value = data.Substring(data.IndexOf(index) + index.Length); if (value.Contains("|")) value = value.Remove(value.IndexOf("|")); return value; } [PunRPC] private void LoadID(int viewID, int MyId) { PhotonView.Find(viewID).gameObject.GetComponentInChildren<Profile2>().MyId = MyId; } }
I'm guessing you didn't write this code? The name looks to be stored in your database or Photon system, and MyID contains the primary key. You probably don't want to query by name, there are most likely users with the same name. Are you actually asking your users for their name, state, gender and age?
So, what are the contents of myWeb.php? I'm going to guess though that myWeb.php doesn't exist, which is what you're asking help for. You're going to need to learn PHP, a bit of HTML, and how to access a MySQL or similar database in order to get this going. You're unlikely to find someone on the forum to write this all for you for free, nor is it a good idea for you to be running your own database while not knowing how to access/secure it yourself. Though you could try Unity Connect and see if anyone is available for a bit of money. If you don't want to learn any of that or pay for someone to write it all for you, I'd suggest going a different route. Such as one of the available database as a service providers.
this script is work i have database and yes i create 3D chat and profile must this script is work i have database and yes i create 3D chat and profile it has to be data name state gender ect
Unfortunately I don't follow. Delete what line, what money? This forum provides free assistance. Have you already prompted the user for their name, and created a profile for them? If so, then pass the myID to your service and return their name. Also as requested, please show the contents of myWeb.php. And you are capturing private information, you need to consider user privacy issues.
Here Is script with name load data why pls not load data but fount from thisplayername? Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Runtime.Serialization.Formatters.Binary; using System.IO; using System; using UnityEngine.UI; public class Profile3 : MonoBehaviour { public string[] items; public string ID; public string Name; public string State; public string Sex; public string Age; private PhotonView photonView; public GameObject ThisPlayer; public GameObject myPlayerName; public int viewID; public string ThisPlayerName; void Start() { photonView = this.gameObject.GetComponent<PhotonView>(); ThisPlayerName = PlayerPrefs.GetString("Player"); viewID = photonView.viewID; StartCoroutine(LoadProfile()); if (photonView.isMine) { photonView.RPC("LoadID", PhotonTargets.AllBuffered, this.viewID, this.ThisPlayerName ); this.viewID = viewID; this.ThisPlayerName = ThisPlayerName; } } IEnumerator LoadProfile() { WWW itemsData = new WWW("myweb.php"); yield return itemsData; string itemsDataString = itemsData.text; print(itemsDataString); items = itemsDataString.Split(';'); ID = (GetDataValue(ThisPlayerName , "ID:")); Name = (GetDataValue(ThisPlayerName, "Name:")); State = (GetDataValue(ThisPlayerName, "State:")); Sex = (GetDataValue(ThisPlayerName, "Sex:")); Age = (GetDataValue(ThisPlayerName, "Age:")); this.gameObject.name = Name; this.myPlayerName.GetComponent<TextMesh>().text = Name; } string GetDataValue(string data, string index) { string value = data.Substring(data.IndexOf(index) + index.Length); if (value.Contains("|")) value = value.Remove(value.IndexOf("|")); return value; } [PunRPC] private void LoadID(int viewID, string ThisPlayerName) { PhotonView.Find(viewID).gameObject.GetComponentInChildren<Profile3>().ThisPlayerName = ThisPlayerName; } }
Your myWeb.php is what communicates with your database, we need to see the contents of this file, please copy and paste it here.
Code (CSharp): <?php $servername = "server"; $username = "name"; $password = "pass"; $dbName = "name"; //Make Connection $conn = new mysqli($servername, $username, $password, $dbName); //Check Connection if(!$conn){ die("Connection Failed. ". mysqli_connect_error()); } $sql = "SELECT ID, Name, State ,Sex ,Age FROM Profile"; $result = mysqli_query($conn ,$sql); if(mysqli_num_rows($result) > 0){ //show data for each row while($row = mysqli_fetch_assoc($result)){ echo "ID:".$row['ID'] . "|Name:".$row['Name']. "|State:".$row['State']. "|Sex:".$row['Sex'] . "|Age:".$row['Age'] .";"; } } ?>
Got it! Actually there is no need to pass in anything with that query, there is no WHERE clause! it just returns everything. And you definitely should not be passing in username and password! So whether you pass in an ID or username, it is just ignored anyway. And you shouldn't be talking directly to a database from a mobile device as each request will create a new connection. Your db will fall over quickly. To be clear, the user name that you are trying to pass in is actually the database administrator. Since it doesn't change, you can just hard-code that right into the php script. It's not the player name. But to back up a bit, if you are just learning Unity, this is not the best way to learn, and you will likely get frustrated and give up. Best to go through some tutorials first.
Google for "Unity tutorials". Here is one source https://unity.com/learn But you won't find one specifically for what you are trying to do with a database because it is not a recommended approach.
Sorry, I don't understand. You might want to contact the original author of the script. If you really want to use the database, then follow my advice. If you have a specific question on my recommendation, please ask.
If I am Understanding you correctly you first said And in the code you provided you could not really accomplish that without a massive amount of work because from what I can tell MyID was the name of the database that was being queried to provide the information. You can not use name to load the data because it is already a column in the database. And Next you are doing an awful lot just to connect to the database. you should have one connection file to connect to the database would look like this Code (PHP): <?php if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly'); /* Database config */ $db_host = 'server'; $db_user = 'username'; $db_pass = 'password'; $db_database = 'database name'; /* End config */ /* Make Connection */ $link = mysqli_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection'); mysqli_select_db ( $link , $db_database ); mysqli_query($link, "SET names UTF8"); /* End connection config */ ?> Then you use another PHP code to actually query your Database. Code (PHP): <?php /* get results from database */ $result = mysqli_query($link,"SELECT id,name,state,sex,age FROM database WHERE MyID='['Name']}'") or die(mysqli_error()); while($row = mysqli_fetch_array( $result, MYSQLI_BOTH)) { echo "ID:".$row['ID'] . "|Name:".$row['Name']. "|State:".$row['State']. "|Sex:".$row['Sex'] . "|Age:".$row['Age']'; } ?>
Please keep in mind that is just an example and altho I changed a few elements, it WILL NOT WORK copied and pasted in your area, you will have to change a few things to make it work properly, especially the part that says Where MyID=['Name'] and if I am not mistaken just at a quick glance I think if you used that format, especially without setting a session, every person who logged in would see your database, because not only are you calling it, and querying it, you are also telling it to echo its contents.
Thank you but I probably use other way save and load data on server from name....is there any instruction?