我在Unity3d中有一个注册表格,如下所示:
IEnumerator CreateAccount()
{
//Sending messages to php script
Debug.Log("button pressed");
WWWForm Form = new WWWForm();
Form.AddField("emailPost", CEmail);
Form.AddField("passwordPost", CPassword);
WWW CreateAccountWWW = new WWW(CreateAccountUrl, Form);
// Wait for the php to send a response
yield return CreateAccountWWW;
if (CreateAccountWWW.error != null)
{
Debug.LogError("Cannot Connect to Account Creation");
Debug.Log(CreateAccountWWW.error);
}
else
{
Debug.Log(CreateAccountWWW.text);
string CreateAccountReturn = CreateAccountWWW.text;
if (CreateAccountReturn == "Success")
{
Debug.Log("Success: Account created");
currentMenu = "Login";
}
}
}
我的协程看起来像这样:
<?php
$db_name = "mydata";
$mysql_username = "root";
$mysql_password = "";
$server_name = "localhost";
$conn = mysqli_connect($server_name, $mysql_username, $mysql_password, $db_name);
if($conn){
echo "Connection Succesful";
}
else{
echo "Connection Not Succesful";
}
?>
我的连接PHP文件如下所示:
<?php
require "conn.php";
$Email = $_POST["emailPost"];
$Password = $_POST["passwordPost"];
if(!$Email || !$Password){
echo "Empty";
}else{
$SQL = "SELECT * FROM users WHERE Email = '" . $Email ."'";
$Result = mysqli_query($conn,$SQL) or die("DB Error");
$Total = mysqli_num_rows($Result);
if($Total == 0){
$insert = "INSERT INTO 'users' ('Email', 'Password') VALUES ('" . $Email . "', MD5('" . $Password . "'))";
$SQL1 = mysqli_query($conn, $insert);
echo "Success";
}else{
echo "AlreadyUsed"; //if user exists
}
}
?>
最后我创建新用户的PHP如下所示:
users
我还有一张我的数据库图片:
一切似乎工作得很好,因为我到处都成功触发了。但是新数据不会进入我的{{1}}表。
我做错了什么?