- Home /
mySQL : Values not inserting to my database
Hi, i am using mySQL. The code snippet below is what i have coded to make sure that the data are stored into the database. In the console, i get this "insert values into database. But it is not updating my datbases. Anyone know what wrong?? And i feel quite weird regarding the way i insert the value of monitorID and playerID. For monitorID, it is auto increment, so i am suspecting that it is the correct way to put 1. Another thing is the playerID, i don't know how am i going to get the iD? hmm
I understand we need to prevent cheating from client, which mean that the server will be responsible for updating the database. So for my case, my client will update the database. This is an for monitoring purpose. So i just want to record what the player have click. It is fine if i do it this way? Or i have to inform the server (using builtin master server) and ask the server to do the updating? Any advice or sugggestion?
Thank you for spending time to read. :)
/***************** connect database, initialization **************/
// MySQL instance specific items
var constr = "Server=localhost;Database=games;UserID=chinese;Password=chinesegames;Pooling=true";
// connection object
var con;
// command object
var cmd;
// reader object
var rdr;
// object collection array
var bodies : GameObject[];
var saving = false;
var loading = false;
// collection container
var _GameItems;
// values to match the database columns
var monitorID;
var playerID;
var radical00;
var radical0;
var fullWord;
var wrong = " ";
var teacherComment = " ";
/********************** end of connection to database **********************/
/********************** saving data into monitor table *************************/
saving = true;
var query;
var levelname = Application.loadedLevelName;
var radical00 = selected_00.GetComponent(textOnMouse00).thisRadical.Ctext;
var radical0 = selected_0.GetComponent(textOnMouse0).thisRadical.Ctext;
var fullWord = selected_0.GetComponent(textOnMouse0).thisRadical.form;
var teacherComment = " ";
if(isWrong)
wrong = "True";
else
wrong = "False";
// Error trapping in the simplest form
try
{
query = "INSERT INTO monitor(monitorID, playerID, gameLevel,radical00, radical0,fullWord, wrong, teacherComment) VALUES (1,1, ?gameLevel,?radical00, ?radical0, ?fullWord, ?wrong, ?teacherComment)";
if (con.State.ToString() != "Open")
{
con.Open();
var cmd = new MySql.Data.MySqlClient.MySqlCommand(query, con);
//var oParam = cmd.Parameters.AddWithValue("?monitorID", monitorID);
//var oParam1 = cmd.Parameters.AddWithValue("?playerID", playerID);
var oParam2 = cmd.Parameters.AddWithValue("?gameLevel", levelname);
var oParam3 = cmd.Parameters.AddWithValue("?radical00", radical00);
var oParam4 = cmd.Parameters.AddWithValue("?radical0", radical0);
var oParam5 = cmd.Parameters.AddWithValue("?fullWord", radical00);
var oParam6 = cmd.Parameters.AddWithValue("?wrong", wrong);
var oParam7 = cmd.Parameters.AddWithValue("?teacherComment", teacherComment);
cmd.ExecuteNonQuery();
print("insert values into database");
}
}
catch (ex)
{
Debug.Log(ex.ToString());
}
// you could also use the update if you know the ID of the item already saved
saving = false;
}
Your answer
Follow this Question
Related Questions
Setup mySQL, insert value to mySQL, retrieve data from mySQL 0 Answers
Finish setup php, how to communicate with mySQL and unity 2 Answers
c# database connection on debian server 0 Answers
How to use php to update mySQL 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers