我正在尝试向表中添加包含数据的新行,这应该很简单,但是我发现这很困难,我确定自己一切都正确,但是只是没有添加条目,只是抛出了净值向真正知道如何做的人寻求帮助。
这是添加条目的C#代码。
public IEnumerator CreateUser(string username, string email, string password, string lastLogin, int currency, int guildID, string guildName, int accountLevel, int rank,
int marchCap, int marchLimit, int buildingQueueLimit, int gold, int silver, int bronze, int buildingMaterials, int metal, int food, int t1Soldiers, int t2Soldiers,
int t3Soldiers, int mainHallLevel, int barracksLevel, int foodStorageLevel, int metalStorageLevel, int buildingMaterialsStorageLevel, int wallsLevel)
{
WWWForm form = new WWWForm();
form.AddField("usernamePost", username);
form.AddField("emailPost", email);
form.AddField("passwordPost", password);
form.AddField("lastloginPost", lastLogin);
form.AddField("currencyPost", currency);
//System
form.AddField("guildIDPost", guildID);
form.AddField("guildNamePost", guildName); form.AddField("accountLevelPost", accountLevel);
form.AddField("rankPost", rank); form.AddField("marchCapPost", marchCap);
form.AddField("marchLimitPost", marchLimit); form.AddField("buildingQueueLimitPost", buildingQueueLimit);
Debug.Log("System data sent.");
//Resources
form.AddField("goldPost", gold); form.AddField("silverPost", silver); form.AddField("bronzePost", bronze);
form.AddField("buildingMaterialsPost", buildingMaterials); form.AddField("metalPost", metal); form.AddField("foodPost", food);
Debug.Log("Resource data sent.");
//Troops
form.AddField("t1SoldiersPost", t1Soldiers); form.AddField("t2SoldiersPost", t2Soldiers); form.AddField("t3SoldiersPost", t3Soldiers);
Debug.Log("Unit data sent.");
//Buildings
form.AddField("mainHallLevelPost", mainHallLevel); form.AddField("barracksLevelPost", barracksLevel); form.AddField("foodStorageLevelPost", foodStorageLevel);
form.AddField("metalStorageLevelPost", metalStorageLevel); form.AddField("buildingMaterialsStorageLevelPost", buildingMaterialsStorageLevel); form.AddField("wallsLevelPost", wallsLevel);
Debug.Log("Build data sent. data sent.");
Debug.Log("Sending Data...");
WWW www = new WWW(createUserURL, form);
yield return www;
Debug.Log("User created : "+username+" / "+email+" / "+password+" / "+lastLogin+" / "+currency+"\n");
Debug.Log(www.text);
}
然后使用以下命令对其进行测试:
void Update () {
if (Input.GetKeyDown(KeyCode.B))
{
StartCoroutine( CreateUser(InputUsername, InputEmail, InputPassword, currentDate, PlayerData.sharedInstance.plat, PlayerData.sharedInstance.guildID, PlayerData.sharedInstance.guild_Name,
PlayerData.sharedInstance.accountLevel, PlayerData.sharedInstance.rank, PlayerData.sharedInstance.march_Capacity
, PlayerData.sharedInstance.max_March_Limit, PlayerData.sharedInstance.buildingQueueLimit, PlayerData.sharedInstance.gold,
PlayerData.sharedInstance.silver, PlayerData.sharedInstance.bronze,
PlayerData.sharedInstance.amt_Building_Materials, PlayerData.sharedInstance.amt_Metal, PlayerData.sharedInstance.amt_Food, PlayerData.sharedInstance.tier_1_Soldier,
PlayerData.sharedInstance.tier_2_Soldier, PlayerData.sharedInstance.tier_3_Soldier, PlayerData.sharedInstance.main_Hall_Level, PlayerData.sharedInstance.barracks_Level,
PlayerData.sharedInstance.food_Storage_Level, PlayerData.sharedInstance.metal_Storage_Level, PlayerData.sharedInstance.buildingMats_Storage_Level,
PlayerData.sharedInstance.walls_Level) );
}
}
然后在PHP中我使用:
$username = $_POST["usernamePost"];
$email = $_POST["emailPost"];
$password = $_POST["passwordPost"];
$lastlogin = $_POST["lastloginPost"];
$currency =$_POST["currencyPost"];
$guildID = $_POST["guildIDPost"];
echo("guildIDPost : ".$guildID."\n");
$guildName = $_POST["guildNamePost"];
echo("guildNamePost : ".$guildName."\n");
$accountLevel = $_POST["accountLevelPost"];
echo("accountLevelPost : ".$accountLevel."\n");
$rank = $_POST["rankPost"];
echo("rankPost : ".$rank."\n");
$marchCap = $_POST["marchCapPost"];
echo("marchCapPost : ".$marchCap."\n");
$marchLimit =$_POST["marchLimitPost"];
echo("marchLimitPost : ".$marchLimit."\n");
$buildingQueueLimit = $_POST["buildingQueueLimitPost"];
echo("buildingQueueLimitPost : ".$buildingQueueLimit."\n");
$gold = $_POST["goldPost"];
echo("goldPost : ".$gold."\n");
$silver = $_POST["silverPost"];
echo("silverPost : ".$silver."\n");
$bronze = $_POST["bronzePost"];
echo("bronzePost : ".$bronze."\n");
$buildingMaterials = $_POST["buildingMaterialsPost"];
echo("buildingMaterialsPost : ".$buildingMaterials."\n");
$metal = $_POST["metalPost"];
echo("metalPost : ".$metal."\n");
$food = $_POST["foodPost"];
echo("foodPost : ".$food."\n");
$t1Soldiers = $_POST["t1SoldiersPost"];
echo("t1SoldiersPost : ".$t1Soldiers."\n");
$t2Soldiers = $_POST["t2SoldiersPost"];
echo("t2SoldiersPost : ".$t2Soldiers."\n");
$t3Soldiers = $_POST["t3SoldiersPost"];
echo("t3SoldiersPost : ".$t3Soldiers."\n");
$mainHallLevel = $_POST["mainHallLevelPost"];
echo("mainHallLevelPost : ".$mainHallLevel."\n");
$barracksLevel = $_POST["barracksLevelPost"];
echo("barracksLevelPost : ".$barracksLevel."\n");
$foodStorageLevel = $_POST["foodStorageLevelPost"];
echo("foodStorageLevelPost : ".$foodStorageLevel."\n");
$metalStorageLevel = $_POST["metalStorageLevelPost"];
echo("metalStorageLevelPost : ".$metalStorageLevel."\n");
$buildingMaterialsStorageLevel = $_POST["buildingMaterialsStorageLevelPost"];
echo("buildingMaterialsStorageLevelPost : ".$buildingMaterialsStorageLevel."\n");
$wallsLevel = $_POST["wallsLevelPost"];
echo("wallsLevelPost : ".$wallsLevel."\n");
// $ = $_POST["Post"];
$conn = new mysqli($servername, $serverusername, $serverpassword, $dbname);
if(!$conn){
die("connection failed". mysqli_connect_error());
}
$sql = "INSERT INTO UserAccounts ( Username, Email, Password, LastLogin, Currency,
GuildID,
GuildName,
AccountLevel,
Rank,
MarchCap,
MarchLimit,
BuildingQueueLimit,
Gold,
Silver,
Bronze,
BuildingMaterials,
Metal,
Food,
T1Soldiers,
T2Soldiers,
T3Soldiers,
MainHallLevel,
BarracksLevel,
FoodStorageLevel,
MetalStorageLevel,
BuildingMaterialsStorageLevel,
WallsLevel)
VALUES ('".$username."','".$email."','".$password."','".$lastlogin."','".$currency."',
'".$guildID."',
'".$guildName."',
'".$accountLevel."',
'".$rank."',
'".$marchCap."',
'".$marchLimit."',
'".$buildingQueueLimit."',
'".$gold."',
'".$silver."',
'".$bronze."',
'".$buildingMaterials."',
'".$metal."',
'".$food."',
'".$t1Soldiers."',
'".$t2Soldiers."',
'".$t3Soldiers."',
'".$mainHallLevel."',
'".$barracksLevel."',
'".$foodStorageLevel."',
'".$metalStorageLevel."',
'".$buildingMaterialsStorageLevel."',
'".$wallsLevel."')";
$result = mysqli_query($conn, $sql);
if(!result) echo "Error";
这一切仅适用于用户名,电子邮件,密码,lastlogin,即时性,我对其进行了测试,并且能够以这种方式添加条目,我计划链接一个用于玩家数据的表,并在其中自动创建一个条目当从login / createuser表中创建一个条目但它不起作用时,我确实将主键链接到外键,尝试设置触发器,但它不起作用,我不是真的精通php还是mysql,这是很新的东西,但是我试图理解为什么这行不通,因为我回显了变量并且它们是正确的,所以帖子消息是正确的,看来它只是不发送查询?也许?
非常感谢您的帮助。