I want to send data from my game to the Database on the server. In this case, I develop locally but when I click the spacebar button The Database is created but With empty data. No data is sent from my game.
I have to try to improve my code also try to implement the pre statements. I am not able to use the unitywebrequest because my version of UNITY3D does not have it my version is 5.0.0f4 When I try to insert the data by hand on fields in the editor and then start the preview, and click the spacebar to send the data, but when I click the database create a row but with empty data, what I fail here, can't find the problem Also, i have aply the debug.log to see if there is any info send from my app to the script and the data is there but i continue not understand why is my code not work correctly, i also provide the prints of the app and database. I also edit again to make the password hash changes i just did but i dont know if is correct like this
!https://imgur.com/J5R56Xf
!https://imgur.com/pzd7t4e
!https://imgur.com/x9VRK6P
This is my unity code below.
using UnityEngine;
using System.Collections;
public class DataInserter : MonoBehaviour {
public string inputUserName;
public string inputPassword;
public string inputEmail;
public string regdata;
string CreateUserURL = "localhost/InsertUser.php";
// Use this for initialization
void Start () {
//regdata = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Space)) CreateUser(inputUserName, inputPassword, inputEmail, regdata);
}
public void CreateUser(string username, string password, string email, string regdata){
WWWForm form = new WWWForm();
form.AddField("usernamePost", username);
form.AddField("passwordPost", password);
form.AddField("emailPost", email);
form.AddField("regdataPost", regdata);
WWW www = new WWW(CreateUserURL, form);
}
}
And This is my New PHP code below.
//Variables for the connection
$servername = "localhost";
$server_username = "root";
$server_password = "mysql";
$dbName = "wizard2019";
$saveuser = "INSERT INTO users (username, email, password, regdata)
VALUES ('".$username."','".$email."','".$password."','".$regdata."')";
//Variable from the user
$username = $_POST["usernamePost"];
$email = $_POST["emailPost"];
$password = password_hash($_POST["passwordPost"], PASSWORD_DEFAULT);
$regdata = $_POST["regdataPost"];
//$username = "helder";
//$email = "test email";
//$password = "123456";
//$regdata = "20201123";
//Make Connection
$conn = new mysqli($servername, $server_username, $server_password, $dbName);
//Check Connection
if(!$conn){
die("Connection Failed. ". mysqli_connect_error());
}
$sql = $saveuser;
$result = mysqli_query($conn ,$sql);
if(!$result) echo "there was an error";
else echo "Registration Sucessfull";
?>