Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
 I am trying to create a LOGIN/REGISTER solution for my app developed via Unity 3D (version 2017.3.0f3). The MySQL DB is located in a paid hosting service in order to avoid restrictions usually caused by FREE hosting services. For some weird reason, it looks like the method Mysqli_fetch_row($return) is ALWAYS returning a NULL value. The Connection to the DB is successful. The query seems to return a NON-NULL value. The $return variable seems also to be a NON-NULL value. The only variable that is a NULL value is the $row, which receives the value from the method Mysqli_fetch_row($return). I have already checked the PHP and C# codes thousands of times and cannot figure out what is wrong. Please HELP !!! I am totally STUCK on this.

 I am constantly getting "INVALID E-MAIL OR PASSWORD" in UNITY Login/Register scene because I only receive NULL values from the PHP.
 Also, I always get the SAME Warning Messages below:

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/storage/4/cf/2c/arcards/public_html/action_login.php on line 33

Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, null given in /home/storage/4/cf/2c/arcards/public_html/action_login.php on line 35
{"success":false,"error":"invalid email or password"}

Please check the CODE PHP and C# below:


PHP
<?php

//CONNECTION TO THE DATABASE
$dbuser = 'usersdb';
$dbpassword = 'Ierushalaim73';
$db = 'usersdb';
$dbhost = 'usersdb.mysql.dbaas.com.br';
$dbport = 3306;
$dblink = mysqli_init();
$dbconnection = mysqli_real_connect($dblink, $dbhost, $dbuser, $dbpassword,         $db, $dbport);

//$dbconnection = mysqli_connect("usersdb.mysql.dbaas.com.br","usersdb","Ierushalaim73","usersdb");

if($dbconnection){
echo "success";
   } else{
   die("Connection failed" . mysql_error());
   }

//LOGIN CODE
$email = $_POST['email'];
$upass = $_POST['password'];
$email = strip_tags($email);
$upass = strip_tags($upass);
$password = hash('sha256', $upass);

$query = "SELECT userEmail FROM activeusers WHERE userEmail='$email' AND userPass='$password'";

$result = mysqli_query($dbconnection,$query);
$row = mysqli_fetch_row($result);

if ($row){
$dataArray = array('success' => true , 'error' => ' ');
  } else {
  $dataArray = array('success' => false, 'error' => 'invalid email or password');
}

header('Content-Type: application/json');
echo json_encode($dataArray);
?>





C# CODE:


using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Runtime.InteropServices.ComTypes;
using UnityEngine;
using UnityEngine.UI;

public class AuthenticationManager : MonoBehaviour {

public GameObject ButtonLogin;
public GameObject ButtonSwapRegistration;
public GameObject ButtonRegister;
public GameObject mainmenu;

public GameObject FieldEmailAddress;
public GameObject FieldPassword;
public GameObject FieldReenterPassword;

public Text textEmail;
public Text textPassword;
public Text textReenterPassword;
public Text textSwapButton;
public Text textFeedback;

public bool showRegistration = false;

WWWForm form;


// Use this for initialization
void Start ()
{
    textFeedback.text = "";
    displayLoginPanel();

}

// Update is called once per frame
void Update () {

}

public void displayLoginPanel()
{
    ButtonRegister.SetActive(false);
    FieldReenterPassword.SetActive(false);
}

public void SwapSignupSignin()
{
    if (showRegistration)
    {
        showRegistration = false;
        ButtonLogin.SetActive(true);
        ButtonRegister.SetActive(false);
        FieldReenterPassword.SetActive(false);
        textSwapButton.text = "SignUp";
    }
    else
    {
        showRegistration = true;
        ButtonLogin.SetActive(false);
        ButtonRegister.SetActive(true);
        FieldReenterPassword.SetActive(true);
        textSwapButton.text = "SignIn";
    }

}

public void RegisterButtonTapped()
{
    textFeedback.text = "Processing registration...";

}

public void LoginButtonTapped()
{
    textFeedback.text = "Loggin in...";
    StartCoroutine("RequestLogin");

}

public IEnumerator RequestLogin()
{
    string email = textEmail.text;
    string password = textPassword.text;

    form = new WWWForm();
    form.AddField("email", email);
    form.AddField("password", password);

    WWW w = new WWW("http://www.arcards.net/action_login.php", form);
    yield return w;

    if (string.IsNullOrEmpty(w.error))
    {
        if (w.text.Contains("invalid email or password"))
        {
            textFeedback.text = "invalid email or password";
        }
        else
        {
            textFeedback.text = "Login successfull...";
        }

    }
    else
    {
        textFeedback.text = "An error occured...";
    }
}

}


What I have tried:

I tried to isolate the variable responsible for the NULL value. It seems that the NULL is coming from the $row=Mysqli_fetch_row ($return).
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900