using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using System.Text;
using TMPro;
public class login2 : MonoBehaviour
{
public TMP_InputField IF_email;
public TMP_InputField IF_pass;
private string serverUrl = "http://localhost/connect2.php"; // Replace with your server URL
void Start()
{
}
IEnumerator SendDataToServer(string name)
{
// Prepare JSON data
string jsonData = "{\"name\":\"" + name + "\"}";
byte[] postData = Encoding.UTF8.GetBytes(jsonData);
// Create request
using (UnityWebRequest request = new UnityWebRequest(serverUrl, "POST"))
{
request.uploadHandler = new UploadHandlerRaw(postData);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
Debug.Log("Response: " + request.downloadHandler.text);
}
else
{
Debug.LogError("Error: " + request.error);
}
}
}
public void loginSubmission()
{
string email = IF_email.text;
string password = IF_pass.text;
//http://localhost/login.php?email=eee@gmail.com&pass=345
serverUrl = $"http://localhost/login.php?email={email}&pass={password}";
//Debug.Log(serverUrl);
StartCoroutine(SendDataToServer("Unity User"));
}
}