Hi,
I am trying to get some information from Google Play Services and send it to a MySQL database. Now I can get the ID and Username…but I can’t send it to the database. Following my C# script and php scripts (I changed some variables like server, database stuff for this example):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class ShowUserInfo : MonoBehaviour
{
public Text UserNameText;
public Text UserIDText;
public Text EmailText;
void Awake()
{
Social.localUser.Authenticate (ProcessAuthentication);
}
void Start()
{
RegisterUser(UserIDText.text, UserNameText.text);
}
private void ProcessAuthentication (bool success)
{
if (success)
{
UserNameText.text = Social.localUser.userName;
UserIDText.text = Social.localUser.id;
}
else
{
Debug.LogWarning ("Failed to authenticate");
}
}
public IEnumerator RegisterUser(string loginUserID, string loginUserName)
{
WWWForm form = new WWWForm();
using (UnityWebRequest www = UnityWebRequest.Post("http://server.com/app/insert.php", form))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log(www.downloadHandler.text);
}
}
}
}
<?php
$servername = "mydatabaseserver";
$username = "databaseusername";
$password = "databasepass";
$dbName = "databasename";
$loginUserID = $_POST["loginUserID"];
$loginUserName = $_POST["loginUserName"];
//Make Connection
$conn = new mysqli($servername, $username, $password, $dbName);
//Check Connection
if(!$conn) {
die("Connection Failed. ". mysqli_connect_error());
}
$sql = "INSERT INTO users (userid, username) VALUES ($loginUserID, '" . $loginUserName . "')";
$result = mysqli_query($conn, $sql);
echo ($sql);
?>
Thanks for any help on this.