[英]Cannot register user on my website (PHP, Unity3D)
我有一個網站,我想將其用作存儲我在Unity3D中制作的多人游戲數據(如用戶名,密碼等)的地方。
現在,我想使用C#和Unity3D注冊某人(將用戶名和密碼添加到MySQL數據庫)。 我使用WWW類與網站進行交流。 以我的觀點,我在Unity3D中編寫的代碼可以正常工作,但是當我訪問phpMyAdmin並搜索新的注冊用戶時,找不到它。 所以我想,問題一定出在PHP腳本中,但是我找不到。
再次出現的問題是用戶名和密碼未添加到MySQL表中。
我將發布兩個腳本,盡管我認為Unity3D中的腳本可以正常工作。 請注意,我絕對是PHP初學者。
<?php
$mysql_host = "example.host.com";
$mysql_database = "example_database";
$mysql_user = "exampleuser";
$mysql_password = "toomanysecrets";
try
{
$toQuery = 'SELECT name,
password
FROM basicUserInfo
ORDER BY name';
if ($_POST["name"] || $_POST["password"])
{
$conn = new PDO("mysql:host=$mysql_host;dbname=$mysql_database", $mysql_user, $mysql_password);
echo "Connected to $mysql_database at $mysql_host successfully!";
$forQuery = 'INSERT INTO `a1936371_userinf`.`basicUserInfo` (
`name` ,`password`
)
VALUES (
\'$_POST[\'name\']\', \'$_POST[\'password\']\'
)';
if (!$conn->query($forQuery))
{
echo "Failed to add data!";
}
else
{
echo "Added data sucessfully";
}
//Close the connection
$conn = null;
}
} catch (PDOException $pe)
{
die("Could not connect to the database $mysql_database:" . $pe->getMessage());
}
Unity3D:
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
Register("testt", "test1");
}
}
public void Register(string playername, string password)
{
StartCoroutine(RegisterOnServer(playername, password));
}
IEnumerator RegisterOnServer(string playerName, string password)
{
string url = "http://deathrunserv.net16.net/index.php";
WWWForm form = new WWWForm();
form.AddField("name", playerName);
form.AddField("password", password);
WWW www = new WWW(url);
yield return www;
Debug.Log("Done!");
}
在您的C#代碼中,您沒有在任何地方使用WWWForm。 嘗試:
WWWForm form = new WWWForm();
form.AddField("name", playerName);
form.AddField("password", password);
WWW www = new WWW(url, form);
yield return www;
Debug.Log("Done!");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.