I'm trying to add new row with data to a table, should be simple but i'm finding it pretty difficult, i was sure i had everything correct but it just doesn't add the entry, just throwing the net out for some help from someone who knows actually how to do this.
here is the c# code to add the entry.
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+"
");
Debug.Log(www.text);
}
Then for testing it's called using this :
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) );
}
}
Then in PHP i use :
$username = $_POST["usernamePost"];
$email = $_POST["emailPost"];
$password = $_POST["passwordPost"];
$lastlogin = $_POST["lastloginPost"];
$currency =$_POST["currencyPost"];
$guildID = $_POST["guildIDPost"];
echo("guildIDPost : ".$guildID."
");
$guildName = $_POST["guildNamePost"];
echo("guildNamePost : ".$guildName."
");
$accountLevel = $_POST["accountLevelPost"];
echo("accountLevelPost : ".$accountLevel."
");
$rank = $_POST["rankPost"];
echo("rankPost : ".$rank."
");
$marchCap = $_POST["marchCapPost"];
echo("marchCapPost : ".$marchCap."
");
$marchLimit =$_POST["marchLimitPost"];
echo("marchLimitPost : ".$marchLimit."
");
$buildingQueueLimit = $_POST["buildingQueueLimitPost"];
echo("buildingQueueLimitPost : ".$buildingQueueLimit."
");
$gold = $_POST["goldPost"];
echo("goldPost : ".$gold."
");
$silver = $_POST["silverPost"];
echo("silverPost : ".$silver."
");
$bronze = $_POST["bronzePost"];
echo("bronzePost : ".$bronze."
");
$buildingMaterials = $_POST["buildingMaterialsPost"];
echo("buildingMaterialsPost : ".$buildingMaterials."
");
$metal = $_POST["metalPost"];
echo("metalPost : ".$metal."
");
$food = $_POST["foodPost"];
echo("foodPost : ".$food."
");
$t1Soldiers = $_POST["t1SoldiersPost"];
echo("t1SoldiersPost : ".$t1Soldiers."
");
$t2Soldiers = $_POST["t2SoldiersPost"];
echo("t2SoldiersPost : ".$t2Soldiers."
");
$t3Soldiers = $_POST["t3SoldiersPost"];
echo("t3SoldiersPost : ".$t3Soldiers."
");
$mainHallLevel = $_POST["mainHallLevelPost"];
echo("mainHallLevelPost : ".$mainHallLevel."
");
$barracksLevel = $_POST["barracksLevelPost"];
echo("barracksLevelPost : ".$barracksLevel."
");
$foodStorageLevel = $_POST["foodStorageLevelPost"];
echo("foodStorageLevelPost : ".$foodStorageLevel."
");
$metalStorageLevel = $_POST["metalStorageLevelPost"];
echo("metalStorageLevelPost : ".$metalStorageLevel."
");
$buildingMaterialsStorageLevel = $_POST["buildingMaterialsStorageLevelPost"];
echo("buildingMaterialsStorageLevelPost : ".$buildingMaterialsStorageLevel."
");
$wallsLevel = $_POST["wallsLevelPost"];
echo("wallsLevelPost : ".$wallsLevel."
");
// $ = $_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";
This all works with just the username, email, password, lastlogin, currecy, i tested it and i was able to add entries this way, i had planned to link a table for player data and have it automatically create an entry there when an entry from the login/createuser table is made but it just wouldn't work, i did link the primary key to the foreign key, tried setting up a trigger but it wouldn't work, i'm not really proficient with php or mysql, it's pretty new but i'm trying to understand why this won't work, the post messages are correct because i echo the variable and they are correct, it seems its just not sending the query? perhaps?
any help is hugely appreciated, thank you.