正在尝试向数据库中添加行,但没有添加条目

xriantvc  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(252)

我正在尝试向一个表中添加包含数据的新行,应该很简单,但我发现这相当困难,我确信我的所有内容都是正确的,但它只是没有添加条目,只是抛出了一个网络,以寻求真正知道如何做的人的帮助。
下面是添加条目的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";

这一切只适用于用户名,电子邮件,密码,上次登录,currecy,我测试了它,我能够添加条目这样,我曾计划链接一个表的球员数据,并让它自动创建一个条目时,从登录/createuser表的条目,但它只是不起作用,我链接主键到外键,尝试设置一个触发器,但它不会工作,我不是很精通php或mysql,这是相当新的,但我试图了解为什么这不会工作,后消息是正确的,因为我回显变量,他们是正确的,似乎只是不发送查询?也许?
非常感谢您的帮助,谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题