DirectAdmin mysql连接到统一游戏问题

问题描述

我已经编写了一个脚本来收集游戏中的电子邮件和得分并将其发送到数据库。到目前为止,在开发过程中我已经使用了MAMP,并且一切正常。现在我将构建上传到直接管理员,在PHPmyadmin上设置数据库,在我的PHP文件中更改了数据库名称密码等,但是它不起作用!我已经将所有文件放在ftp的同一文件夹中(统一构建文件和其中包含PHP脚本的sqlconnect文件夹),但是的,它不会更新数据库

这是数据库

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class Database : MonoBehavIoUr
{
public InputField emailField;
public InputField inputFieldRef;   
public Button submitButton;
// Start is called before the first frame update
public void CallSignup()
{
    StartCoroutine(Signup());
}

IEnumerator Signup()
{
    WWWForm form = new WWWForm();
    form.AddField("email",emailField.text);
    emailField.text = string.Empty;
    form.AddField("score",GameManager.score);
    UnityWebRequest www = UnityWebRequest.Post("http://localhost/sqlconnect/signup.PHP",form);
    yield return www.SendWebRequest();
    
    if(www.isNetworkError || www.isHttpError) {
        Debug.Log(www.error);
    }
    else {
        Debug.Log("Form upload complete!");
    }
}
public void Verifyinput()
{
    submitButton.interactable = (emailField.text.Length >= 8);
}
}

这是我的PHP文件

<?PHP

$servername = "localhost";
$username = "database username";
$password = "password";
$dbname = "database";

$conn = MysqLi_connect($servername,$username,$password,$dbname);

if (MysqLi_connect_errno())
{
    echo "1: Connection Failed";
    exit();
}

$email = msqli_real_escape_string($conn,$_POST["email"];
$emailclean = filter_var($email,FILTER_SANITIZE_STRING,FILTER_FLAG_STRIP_LOW | 
FILTER_FLAG_STRIP_HIGH);
$score = $_POST["score"];

$updatequery = "UPDATE testscore SET score='$score' WHERE email ='$email'";
MysqLi_query($conn,$updatequery) or die("Failed ".__LINE__." : ".MysqLi_error($conn));

echo "0";

?>

解决方法

再次运行检查器后,我看到,因为我没有打开Wildard DNS,它无法连接并显示。所以我添加了标题

header('Access-Control-Allow-Origin: *');

header('Access-Control-Allow-Methods: GET,POST');

header("Access-Control-Allow-Headers: X-Requested-With");

现在我可以看到一切正常