连接到mysql数据库时UNITY 3D登录问题(UNITY 2017.3.0f3) [英] UNITY 3D login issue when connected to a mysql DB (UNITY 2017.3.0f3)

查看:86
本文介绍了连接到mysql数据库时UNITY 3D登录问题(UNITY 2017.3.0f3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 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:

< br $> b $ b



<?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#代码:










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...";
    }
}

}





我尝试过:



我试图隔离负责NULL值的变量。似乎NULL来自$ row = Mysqli_fetch_row($ return)。



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).

推荐答案

return)总是返回NULL值。与DB的连接成功。查询似乎返回NON-NULL值。
return) is ALWAYS returning a NULL value. The Connection to the DB is successful. The query seems to return a NON-NULL value. The


返回变量似乎也是一个NON-NULL值。唯一的NULL值变量是
return variable seems also to be a NON-NULL value. The only variable that is a NULL value is the


行,它从方法Mysqli_fetch_row接收值(
row, which receives the value from the method Mysqli_fetch_row(


这篇关于连接到mysql数据库时UNITY 3D登录问题(UNITY 2017.3.0f3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆