- Home /
How can i connect my unity app made for android to connect with mysql database?,How do i able to make my android app made from Unity connect to Mysql database
Based from the questions above, I've made a simple login and register page for my app for android using unity and i've also created a mysql database using xampp and php. However, when i tested it works on my laptop but when i publish and insert to my phone it doesn't.
Here is the code for my app using unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Registeration : MonoBehaviour {
public InputField nameField;
public InputField passwordField;
public Button submitButton;
public void CallRegister()
{
StartCoroutine(Register());
}
IEnumerator Register()
{
WWWForm form = new WWWForm();
form.AddField("name", nameField.text);
form.AddField("password", passwordField.text);
WWW www = new WWW("http://localhost/sqlconnect/register.php", form);
yield return www;
if (www.text == "0")
{
Debug.Log("User created successfully.");
UnityEngine.SceneManagement.SceneManager.LoadScene("mainmenu");
}
else
{
Debug.Log("User creation failed. Error #" + www.text);
}
}
public void VerifyInputs()
{
submitButton.interactable = (nameField.text.Length >= 8 && passwordField.text.Length >= 8);
}
}
and here's the php code
<?php
$con = mysqli_connect('localhost', 'root', '', 'usersdatabase');
if (mysqli_connect_errno())
{
echo "1: Connection failed";
exit();
}
$username = $_POST["name"];
$password = $_POST["password"];
$namecheckquery = "SELECT username FROM publicusers WHERE username='" . $username . "';";
$namecheck = mysqli_query($con, $namecheckquery) or die("2: Name check query failed");
if (mysqli_num_rows($namecheck) > 0)
{
echo "3: Name already exists";
exit();
}
$salt = "\$5\$rounds=5000\$" . "steamedhams" . $username . "\$";
$hash = crypt($password, $salt);
$insertuserquery = "INSERT INTO publicusers (username, hash, salt) VALUES ('" . $username . "','" . $hash . "', '" . $salt . "');";
mysqli_query($con, $insertuserquery) or die("4: Insert player query failed");
echo("0");
?>
,From the question above, i've made a android app that consists a simple login and register scene using unity and i've created a database using mysql and xampp. So far, I've tested using my laptop and it works but when i publish apk and installed in my phone it doesn't work.
Your answer
Follow this Question
Related Questions
Android Mysql Database online 3 Answers
Unity to PHP/MySQL: password and username security 1 Answer
Javascript with php 1 Answer
Using PHP to generate objects or list in Unity with C# 2 Answers
Web Player and database 1 Answer