Search Unity

Who know very good HTML?

Discussion in 'Scripting' started by gagac42, Sep 6, 2019.

  1. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    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....
     
  2. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    HTML is a markup language, not a scripting language. Are you sure you're on the right forum?
     
    Joe-Censored likes this.
  3. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    Here is script on load profile data in my web site pls help me load data with name no MyID

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Runtime.Serialization.Formatters.Binary;
    5. using System.IO;
    6. using System;
    7. using UnityEngine.UI;
    8. public class Profile2 : MonoBehaviour
    9. {
    10.  
    11.     public string[] items;
    12.     public string ID;
    13.     public static string Name;
    14.     public string State;
    15.     public string Sex;
    16.     public string Age;
    17.     public int MyId;
    18.  
    19.     private PhotonView photonView;
    20.     public GameObject ThisPlayer;
    21.     public GameObject myPlayerName;
    22.     public int viewID;
    23.  
    24.  
    25.  
    26.     void Awake()
    27.     {
    28.         photonView = this.gameObject.GetComponent<PhotonView>();
    29.         MyId = PlayerPrefs.GetInt("MyID");
    30.         viewID = photonView.viewID;
    31.         StartCoroutine(LoadProfile());
    32.         if (photonView.isMine)
    33.         {
    34.             photonView.RPC("LoadID", PhotonTargets.AllBuffered , this.viewID, this.MyId );
    35.             this.viewID = viewID;
    36.             this.MyId = MyId;
    37.  
    38.         }
    39.  
    40.     }
    41.     IEnumerator LoadProfile()
    42.     {
    43.  
    44.         WWW itemsData = new WWW("myWeb.php");
    45.         yield return itemsData;
    46.         string itemsDataString = itemsData.text;
    47.         print(itemsDataString);
    48.         items = itemsDataString.Split(';');
    49.         ID = (GetDataValue(items[MyId], "ID:"));
    50.         Name = (GetDataValue(items[MyId], "Name:"));
    51.         State = (GetDataValue(items[MyId], "State:"));
    52.         Sex = (GetDataValue(items[MyId], "Sex:"));
    53.         Age = (GetDataValue(items[MyId], "Age:"));
    54.  
    55.         this.gameObject.name = Name;
    56.         this.myPlayerName.GetComponent<TextMesh>().text = Name;
    57.  
    58.     }
    59.     string GetDataValue(string data, string index)
    60.     {
    61.         string value = data.Substring(data.IndexOf(index) + index.Length);
    62.         if (value.Contains("|")) value = value.Remove(value.IndexOf("|"));
    63.         return value;
    64.     }
    65.  
    66.  
    67.  
    68.     [PunRPC]
    69.     private void LoadID(int viewID, int MyId)
    70.     {
    71.  
    72.  
    73.         PhotonView.Find(viewID).gameObject.GetComponentInChildren<Profile2>().MyId = MyId;
    74.  
    75.     }
    76. }
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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?
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    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.
     
    Ryiah likes this.
  6. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    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
     
  7. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    My web exist but delede this line help me pls how much you want money?
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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.
     
  9. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    Here Is script with name load data why pls not load data but fount from thisplayername?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Runtime.Serialization.Formatters.Binary;
    5. using System.IO;
    6. using System;
    7. using UnityEngine.UI;
    8. public class Profile3 : MonoBehaviour
    9. {
    10.  
    11.     public string[] items;
    12.     public string ID;
    13.     public string Name;
    14.     public string State;
    15.     public string Sex;
    16.     public string Age;
    17.  
    18.  
    19.     private PhotonView photonView;
    20.     public GameObject ThisPlayer;
    21.     public GameObject myPlayerName;
    22.     public int viewID;
    23.  
    24.     public string ThisPlayerName;
    25.  
    26.     void Start()
    27.     {
    28.         photonView = this.gameObject.GetComponent<PhotonView>();
    29.         ThisPlayerName = PlayerPrefs.GetString("Player");
    30.         viewID = photonView.viewID;
    31.         StartCoroutine(LoadProfile());
    32.         if (photonView.isMine)
    33.         {
    34.             photonView.RPC("LoadID", PhotonTargets.AllBuffered, this.viewID, this.ThisPlayerName );
    35.             this.viewID = viewID;
    36.             this.ThisPlayerName = ThisPlayerName;
    37.  
    38.         }
    39.  
    40.     }
    41.     IEnumerator LoadProfile()
    42.     {
    43.  
    44.         WWW itemsData = new WWW("myweb.php");
    45.         yield return itemsData;
    46.         string itemsDataString = itemsData.text;
    47.         print(itemsDataString);
    48.         items = itemsDataString.Split(';');
    49.         ID = (GetDataValue(ThisPlayerName , "ID:"));
    50.         Name = (GetDataValue(ThisPlayerName, "Name:"));
    51.         State = (GetDataValue(ThisPlayerName, "State:"));
    52.         Sex = (GetDataValue(ThisPlayerName, "Sex:"));
    53.         Age = (GetDataValue(ThisPlayerName, "Age:"));
    54.  
    55.         this.gameObject.name = Name;
    56.         this.myPlayerName.GetComponent<TextMesh>().text = Name;
    57.  
    58.     }
    59.  
    60. string GetDataValue(string data, string index)
    61. {
    62.     string value = data.Substring(data.IndexOf(index) + index.Length);
    63.     if (value.Contains("|")) value = value.Remove(value.IndexOf("|"));
    64.     return value;
    65. }
    66.  
    67.  
    68. [PunRPC]
    69.     private void LoadID(int viewID, string ThisPlayerName)
    70.     {
    71.  
    72.  
    73.         PhotonView.Find(viewID).gameObject.GetComponentInChildren<Profile3>().ThisPlayerName = ThisPlayerName;
    74.  
    75.     }
    76. }
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Your myWeb.php is what communicates with your database, we need to see the contents of this file, please copy and paste it here.
     
    Joe-Censored likes this.
  11. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    Code (CSharp):
    1. <?php
    2.     $servername = "server";
    3.     $username =  "name";
    4.     $password = "pass";
    5.     $dbName = "name";
    6.  
    7.    
    8.     //Make Connection
    9.     $conn = new mysqli($servername, $username, $password, $dbName);
    10.     //Check Connection
    11.     if(!$conn){
    12.         die("Connection Failed. ". mysqli_connect_error());
    13.     }
    14.    
    15.     $sql = "SELECT ID, Name, State ,Sex ,Age FROM Profile";
    16.     $result = mysqli_query($conn ,$sql);
    17.    
    18.    
    19.     if(mysqli_num_rows($result) > 0){
    20.         //show data for each row
    21.         while($row = mysqli_fetch_assoc($result)){
    22.             echo "ID:".$row['ID'] . "|Name:".$row['Name']. "|State:".$row['State']. "|Sex:".$row['Sex'] . "|Age:".$row['Age'] .";";
    23.         }
    24.     }
    25.    
    26.    
    27.    
    28.    
    29.  
    30.  
    31. ?>
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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.
     
  13. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    where to find the tutorial ?
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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.
     
  15. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    ok i need last 2 code my game almost finished I try to ask unity
     
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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.
     
  17. cyberpinoy

    cyberpinoy

    Joined:
    Sep 13, 2018
    Posts:
    8
    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):
    1. <?php
    2.  
    3. if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly');
    4.  
    5.  
    6. /* Database config */
    7.  
    8. $db_host        = 'server';
    9. $db_user        = 'username';
    10. $db_pass        = 'password';
    11. $db_database    = 'database name';
    12.  
    13. /* End config */
    14.  
    15. /* Make Connection */
    16.  
    17. $link = mysqli_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
    18.  
    19. mysqli_select_db ( $link , $db_database );
    20. mysqli_query($link, "SET names UTF8");
    21.  
    22. /* End connection config */
    23.  
    24. ?>
    Then you use another PHP code to actually query your Database.
    Code (PHP):
    1. <?php
    2.          
    3.          /* get results from database */
    4.         $result = mysqli_query($link,"SELECT id,name,state,sex,age FROM database WHERE  MyID='['Name']}'")
    5.                 or die(mysqli_error());
    6.                 while($row = mysqli_fetch_array( $result, MYSQLI_BOTH)) {
    7.                 echo "ID:".$row['ID'] . "|Name:".$row['Name']. "|State:".$row['State']. "|Sex:".$row['Sex'] . "|Age:".$row['Age']';
    8.                 }
    9.                 ?>
     
  18. cyberpinoy

    cyberpinoy

    Joined:
    Sep 13, 2018
    Posts:
    8
    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.
     
  19. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    Thank you but I probably use other way save and load data on server from name....is there any instruction?
     
  20. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Use a proper web service API that in turn talks to the database. This is how commercial games do it.