Troubleshooting PHP Login Script

Hi, I am creating a 2D MMORPG and I successfully created a scene to register a player with the according scripts, once the player registers successfully, it gets stored on my database. I ran into a problem when Logging a player in. For some reason my php script is not working at all, any details i put in, it outputs successful.
I know i should probably debug it further however i spent the entire day building and debugging the registration part…

Here is my c# code:

public class NetworkManager : MonoBehaviour
{

    public const string DATA_URL_SIGNUP = "http://EXAMPLE.com/signup.php";
    public const string DATA_URL_LOGIN = "http://EXAMPLE.com/login.php";
  

    // PRE-Selection

    public Button loginButtonPanel, signupButtonPanel;

    // Login && Signup Panels

    public GameObject loginPanel, signupPanel;

    // Signup Feilds
  
    public InputField usernameSignup, passwordSignup, passwordVerification, age, email;
    public Button joinButton;

    // login Feilds

    public InputField usernameLogin, passwordLogin;
    public Button loginButton;



    void Start()
    {
        loginButtonPanel.onClick.AddListener(OpenLoginPanel);
        signupButtonPanel.onClick.AddListener(OpenSignupPanel);
    }


    void OpenSignupPanel()
    {
        signupPanel.SetActive(true);
        signupButtonPanel.gameObject.SetActive(false);
        loginButtonPanel.gameObject.SetActive(false);

    }


    void OpenLoginPanel()
    {
        loginPanel.SetActive(true);
        signupButtonPanel.gameObject.SetActive(false);
        loginButtonPanel.gameObject.SetActive(false);
    }


    public void SignupComplete()
    {
        // Make sure nothing is blank

        if (usernameSignup.text == "" || passwordSignup.text == "" || passwordVerification.text == "" || age.text == "" || email.text == "")
        {
            return;
        }
      
        // Check if passwords match

        if (passwordSignup.text != passwordVerification.text)
        {
            return;
        }

        // Check Age

        if (int.Parse(age.text)< 13)
        {
            return;
        }

        // IF the client makes it this far, send their data to the website!

        Debug.Log("Processing Request");

        StartCoroutine(ProcessRequest(usernameSignup.text, passwordSignup.text, DATA_URL_SIGNUP, age.text, email.text));

    }

    // ERROR WHEN LOGIN  "ArgumentException: Cannot create a multipart form data section without body data"
    public void LoginComplete()
    {
        if(usernameLogin.text == "" || passwordLogin.text == "" )
        {
            return;
            Debug.Log("Please fill in all fields!");
        }

        Debug.Log("Processing Request");
        StartCoroutine(ProcessRequest(usernameLogin.text, passwordLogin.text, DATA_URL_LOGIN));
      
    }

    IEnumerator ProcessRequest(string username, string password, string url, string age = null, string email = null)
    {
         WWWForm form = new WWWForm();
        form.AddField("username", username);
        form.AddField("password", password);
        form.AddField("age", age != null ? age : "0");
        form.AddField("email", email == null ? "" : email);
        UnityWebRequest www = UnityWebRequest.Post(url, form);
        yield return www.SendWebRequest();

        if (www.result != UnityWebRequest.Result.Success)
        {
            Debug.Log(www.error);
        }
        else
        {
            Debug.Log("Form upload complete!");
        }
    }
  
    }

I tried my best and i think this is working on how i intended…

Here is my php code:

<?php


// Create variables for host, user, pass, dbName.

$dbhost = 'EXAMPLE';
$dbuser = 'EXAMPLE';
$dbpass = 'EXAMPLE';
$dbname = 'EXAMPLE';

// Create a variable to hold connection to mySQL using mysqp_select_db(host, user, pass)

$mysqli= mysqli_connect($dbhost, $dbuser, $dbpass) or die ("ERROR connecting to server");

// Once connected,  select the dbname u want to work with using mysqp_select_db

mysqli_select_db($mysqli, $dbname);

// Create a variable to store username sent from unity
// Create a variable to store password sent from unity
$username = $mysqli-> real_escape_string($_POST['username']);
$password = $mysqli-> real_escape_string($_POST['password']);


// Create a variable to store the query we'd like to run in the db


$query = "SELECT * FROM Players WHERE username = '$username'";

// CHECK if username already exsist
$result = mysqli_query($mysqli, $query) or die ("Error processing request" .mysqli_error());

// CHECK to see if a row returns with a username from unity

while ($row = mysqli_fetch_array($result))
{
    //grab current row of username and compare it to the username recieved.
    if(password_verify($password, $row['password']))
    {
        //we have a matching username & password
        die("LoginSuccess!");
    }
  
}

die ("Username/Password Invalid, Please try again !");

?>

Please can someone help me spot any syntax errors, or bad language :frowning:

Networking, UnityWebRequest, WWW, Postman, curl, WebAPI, etc:

And setting up a proxy can be very helpful too, in order to compare traffic:

Thank you @Kurt-Dekker

1 Like