Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

why i can't send data to phpmyadmin.

Discussion in 'Scripting' started by ZamanZam, Feb 8, 2020.

  1. ZamanZam

    ZamanZam

    Joined:
    Jan 28, 2020
    Posts:
    2
    Code (PHP):
    1. <?php
    2. //Email and password
    3. $Email = $_REQUEST("Email");
    4. $Password = $_REQUEST("Password");
    5.  
    6. //php Only
    7. $Hostname = "";
    8. $DBName = "";
    9. $User = "";
    10. $PasswordP = "";
    11.  
    12. mysql_connect($Hostname,$User,$PasswordP) or die ("Can't connect to DB");
    13. mysql_select_db($DBName) or die ("Can't connect to DB");
    14.  
    15. if(! $Email || !$PasswordP){
    16.     echo "Empty";
    17. }else {
    18.     $SQL = "SELECT * FROM accounts WHERE Email = '" . $Email ."'" ;  
    19.     $Result = @mysql_query($SQL) or die ("DB Error");
    20.     $Total = mysql_num_rows($Result);
    21.     if($Total == 0){
    22.         $insert = "INSERT INTO 'accounts' ('Email','Password') VALUES ('" . $Email . "', MDS('" . $Password . "'))";
    23.         $SQL1 = mysql_query($insert);
    24.         echo "Success";
    25.     }else{
    26.         echo"AlreadyUsed";
    27.     }
    28. }//End Main Else
    29. mysql_close();
    30.  
    31. ?>
    32.  
    33.  
    [C#]
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Networking;

    public class LogIn : MonoBehaviour
    {
    #region Variables

    //Static Variable
    public static string Email = "";
    public string Password = "";

    //Public Variable
    public string CurrentMenu = "Login";


    //Private Variable
    private string CreateAccountUrl = "http://127.0.0.1/CreateAccount.php";
    private string LogInUrl = "";
    private string ConfirmPass = "";
    private string ConfirmEmail = "";
    private string CEmail = "";
    1. private string CPassword = "";


    //GUI Text Section
    public float X;
    public float Y;
    public float Width;
    public float Height;


    #endregion

    // Start is called before the first frame update
    void Start()
    {

    }//End Start Method


    //Main GUI Function
    void OnGUI()
    {
    //If our current menu is = login,the display the login menu
    //By calling our Login GUI function,Else,display the
    //Create account GUI by calling its function

    if (CurrentMenu == "Login")
    {
    //Call login GUI
    LoginGUI();
    }else if (CurrentMenu == "CreateAccount")
    {
    //Call create account GUI
    CreateAccountGUI();
    }
    }//End OnGui


    #region Custom methods

    //This method will login the account
    void LoginGUI()
    {
    //Create box to simulate window
    GUI.Box(new Rect(260,120,400,350), "Log Masuk Akaun Anda");

    //Create account button and login button
    //Open Create Account Window
    if (GUI.Button(new Rect(415,400,100,25) , "Daftar Akaun"))
    {
    CurrentMenu = "CreateAccount";
    }//End Button

    //Log User In
    if (GUI.Button(new Rect(400,365,125,25), "Log Masuk Akaun"))
    {

    }//End Button

    //Email
    GUI.Label(new Rect(300, 214, 285, 23), "Email : ");
    Email = GUI.TextField(new Rect(342,214,285,23) , Email);

    //Password
    GUI.Label(new Rect(276, 255, 285, 23), "Password : ");
    Password = GUI.TextField(new Rect(342,255,285,23), Password);

    }//End Login GUI

    //This method will be the GUI for creating the account
    void CreateAccountGUI()
    {
    //Create box to simulate window
    GUI.Box(new Rect(260, 120, 400, 350), "Daftar Akaun Anda");

    //Email and password,plus confirmation
    GUI.Label(new Rect(300, 214, 285, 23), "Email : ");
    CEmail = GUI.TextField(new Rect(342, 214, 285, 23), CEmail);

    GUI.Label(new Rect(276, 255, 285, 23), "Password : ");
    CPassword = GUI.TextField(new Rect(342, 255, 285, 23), CPassword);

    GUI.Label(new Rect(305, 292, 224, 23), "Confirm Email : ");
    ConfirmEmail = GUI.TextField(new Rect(404, 291, 224, 23), ConfirmEmail);

    GUI.Label(new Rect(290, 330, 285, 23), "Confirm Password : ");
    ConfirmPass = GUI.TextField(new Rect(405, 330, 224, 23), ConfirmPass);

    //Create random int field for bot protection
    //Create Account button,and login button
    //Open Create Acccount Window
    if (GUI.Button(new Rect(415, 400, 100, 25), "Daftar Akaun"))
    {
    if (ConfirmPass == CPassword && ConfirmEmail == CEmail)
    {
    StartCoroutine("CreateAccount");
    }
    else
    {
    //StartCoroutine();
    }
    }//End create account button

    //Log User In
    if (GUI.Button(new Rect(400, 365, 125, 25), "Kembali"))
    {
    CurrentMenu = "Login";

    }//End Button

    }//End Creating Account GUI

    #endregion

    #region CoRoutines
    //Actually Create Account
    [System.Obsolete]
    IEnumerator CreateAccount()
    {
    //This is what sends messages to our php scripts.
    WWWForm Form = new WWWForm();

    //The fields are the variable we are sending.
    Form.AddField("Email", CEmail);
    Form.AddField("Password", CPassword);
    WWW CreateAccountWWW = new WWW(CreateAccountUrl, Form);

    //Wait for php to send something back to unity
    yield return CreateAccountWWW;

    if(CreateAccountWWW.error != null)
    {
    Debug.LogError("Cannnot Connect to Account Creation");
    }
    else
    {
    string CreateAccountReturn = CreateAccountWWW.text;
    if(CreateAccountReturn == "Success")
    {
    Debug.Log("Success : Account Created");
    CurrentMenu = "Login";
    }
    }//End else

    }//End Create Account

    #endregion

    } //End Class[/code]
     
  2. unit_dev123

    unit_dev123

    Joined:
    Feb 10, 2020
    Posts:
    989
    Is problem with php?