Hello,following code dont work to talk to the database! Just nothing happens! When i click on the Button the StartCoroutine will be executed but the script dont talk to the database! Anyone any ideas? Thank you!
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class CreateAccountManager : MonoBehaviour {
//Static Variables
//Variablen für LoginFormular
public static string accountEmail = "";
public static string accountEmailConfirm = "";
public static string accountPassword = "";
public static string accountPasswordConfirm = "";
//Public Variables
//Private Variables
private string createAccountUrl = "http://127.0.0.1/CreateAccount/Test1.php";
//FormInputs
[SerializeField]
private InputField fldAccountUsername;
[SerializeField]
private InputField fldAccountUsernameConfirm;
[SerializeField]
private InputField fldAccountPassword;
[SerializeField]
private InputField fldAccountPasswordConfirm;
[SerializeField]
private Text txtErrorMessage;
// Use this for initialization
void Start () {
fldAccountUsername.contentType = InputField.ContentType.EmailAddress;
txtErrorMessage.text = "";
}
// Update is called once per frame
void Update () {
accountEmail = fldAccountUsername.text;
accountEmailConfirm = fldAccountUsernameConfirm.text;
accountPassword = fldAccountPassword.text;
accountPasswordConfirm = fldAccountPasswordConfirm.text;
}
public void CreateAccountClicked ()
{
if( accountPasswordConfirm == accountPassword && accountEmailConfirm == accountEmail )
{
StartCoroutine ("CreateUserAccount");
}
else
{
txtErrorMessage.text = "Error: Input dont match!";
}
}
IEnumerator CreateUserAccount()
{
WWWForm Form = new WWWForm ();
Form.AddField ("UserEmail", accountEmail);
print (accountEmail);
Form.AddField ("UserPassword", accountPassword);
WWW CreateAccountWWW = new WWW (createAccountUrl, Form);
//Wait for PHP-File!
yield return CreateAccountWWW;
if (CreateAccountWWW.error != null)
{
Debug.LogError ("Cannot Connect to Create Account!");
txtErrorMessage.text = "Error: Cannot Connect to Create Account!";
}
else
{
string CreateAccountReturn = CreateAccountWWW.text;
if(CreateAccountReturn == "Success" )
{
Debug.Log ("Success: Account Created!");
}
}
}
}
edit(moved from answer)
This is the PHP-File to talk to the database:
<?php
//Email and Password
@$UserEmail = $_REQUEST["UserEmail"];
@$UserPassword = $_REQUEST["UserPassword"];
//PHP Only
$servername = "localhost";
$serverUserName = "root";
$serverPassword = "";
$dbName = "login";
$conn = new mysqli($servername, $serverUserName, $serverPassword, $dbName);
if(!$UserEmail || !$UserPassword){
echo"Empty fields!";
} else {
$SQL = "SELECT * FROM accounts WHERE Email = '" . $UserEmail ."'";
$Result = @mysqli_query($conn, $SQL) or die ("Database Error");
$Total = mysqli_num_rows($Result);
if($Total == 0){
$insert = "INSERT INTO 'accounts' ('Email', 'Password') VALUES ('" . $UserEmail . "'. MD5('" . $UserPassword . "')";
$SQL1 = mysql_query($insert);
echo "Success";
} else {
echo "AlreadyUsed";
}
}
//Close Mysq
//mysql_close();
?>
Can anyone help? Thx!