Firstly, I tried to make the problem sound as easy as possible, I'd like to say a big thank you for everyone who takes time to read this. My aim My aim is to be able to tell if a login was successful, and then to identify the player`s name and eventually to be able to modify data from my database from the unity script for that specific player. Basically to learn how the WWW form functions. What do I have at this moment? I have a website set up (I think I`m not allowed to type it here) On the website, you can login and register. The user is added to the database with all of the data that I want to have. In the game, I made a login system, which upon entering the data and pressing the "Login" button, it tells whether your login credentials were correct or if for example the password/username was incorrect. I made it somehow to print in the console whether the login was successful or not, but I do not know how to access "live" print logs in my script. I suppose there is another method to tell whether the user successfully logged in or not. The scripts oldLogin.php Code (CSharp): <?php $servername = "I swear to God this is not the problem"; $server_username = "I swear to God this is not the problem"; $server_password = "I swear to God this is not the problem"; $DBName = "I swear to God this is not the problem"; $user_username = $_POST["usernamePost"]; $user_password = $_POST["passwordPost"]; $conn = new mysqli ($servername, $server_username, $server_password, $DBName); if (!$conn){ die ("Connection Failed.".mysqli_connect_error()); } $sql = "SELECT password FROM users WHERE username = '".$user_username."' "; $result = mysqli_query ($conn, $sql); if (mysqli_num_rows ($result) > 0){ while ($row = mysqli_fetch_assoc($result)){ if ($row['password'] == $user_password){ echo "login success"; } else{ echo "password incorrect"; } } } else{ echo "user not found"; } ?> login.cs Code (CSharp): public InputField userNameIF; // the input field for username public InputField passwordIF; // for password string LoginURL = "http://IdoNotThinkIAmAllowedToShowThis.com/oldLogin.php"; public void submitLogin(){ StartCoroutine (LogInToDB (userNameIF.text, passwordIF.text)); // I call this function upon clicking the Login button } IEnumerator LogInToDB(string username, string password){ WWWForm form = new WWWForm (); form.AddField ("usernamePost", username); form.AddField ("passwordPost", password); WWW www = new WWW (LoginURL, form); yield return www; print (www.text); }
I am not great at PHP and stuff, but I might recommend checking this out, maybe it will help: https://forum.unity.com/threads/php-pdo-login-system-free.446259/
Hi and thank you very much for your interest! The purpose of my project is mainly to help me learn. The link you offered me contains a fairly complicated system which I don't understand. I would really love a solution to my problem, rather than an already scripted system. But still, thank you very much!
I solved my problem using the php script. Instead of echoing "login success", I echoed the $_POST["usernamePost"]. For the else cases, I returned: "failednameOfTheError)" In the c# script, I verified if the sixth characters equals ':', and if not, then the user is logged in with the $_POST["usernamePost"]. I convert www.text into a string, and that is my username.