- Home /
Update mySQL at game runtime ???
I have been using the log in tutorial on the Unity forum and the phphandler scripts up till now with no issues. But I seem to be stuck when it comes to updating the database at run time. I'm pretty sure its my PHP command. See Below:
//////////////////////////////////////////////////////////////////////////////////
$SQL = "SELECT * FROM players WHERE gameName = ' " . $gameName . " ' AND playerPassword = ' " . $playerPassword . " ';";
mysql_query( $SQL ) or die( mysql_error() );
$query = "UPDATE players SET strength = ' " . $strength . " ',' " strengthMax = ' " . $strengthMax . " ',' " agility = ' " . $agility . " ',' " agilityMax = ' " . $agilityMax . " ',' " dexterity = ' " . $dexterity . " ',' " dexterityMax = ' " . $dexterityMax . " ',' " stamina = ' " . $stamina . " ',' " staminaMax = ' " . $staminaMax . " ',' " health = ' " . $health . " ',' " healthMax = ' " . $healthMax . " ',' " intelligence = ' " . $intelligence . " ',' " intelligenceMax = ' " . $intelligenceMax . " ',' " comprehension = ' " . $comprehension . " ',' " comprehensionMax = ' " . $comprehensionMax . " ',' " psyche = ' " . $psyche . " ',' " psycheMax = ' " . $psycheMax . " ',' " mana = ' " . $mana . " ',' " manaMax = ' " . $manaMax . " ',' " lastPosX = ' " . $lastPosX . " ',' " lastPosY = ' " . $lastPosY . " ',' " lastPosZ = ' " . $lastPosZ . " ',' " anchorHead = ' " . $anchorHead . " ',' " anchorLeftHand = ' " . $anchorLeftHand . " ',' " anchorRightHand = ' " . $anchorRightHand . " ',' " anchorChest = ' " . $anchorChest . " ',' " anchorPelvis = ' " . $anchorPelvis . " ',' " anchorRightBicep = ' " . $anchorRightBicep . " ',' " anchorRightForeArm = ' " . $anchorRightForeArm . " ',' " anchorRightWrist = ' " . $anchorRightWrist . " ',' " anchorLeftBicep = ' " . $anchorLeftBicep . " ',' " anchorLeftForeArm = ' " . $anchorLeftForeArm . " ',' " anchorLeftWrist = ' " . $anchorLeftWrist . " ',' " anchorRightThigh = ' " . $anchorRightThigh . " ',' " anchorRightCalf = ' " . $anchorRightCalf . " ',' " anchorRightAnkle = ' " . $anchorRightAnkle . " ',' " anchorLeftThigh = ' " . $anchorLeftThigh . " ',' " anchorLeftCalf = ' " . $anchorLeftCalf . " ',' " anchorLeftAnkle = ' " . $anchorLeftAnkle . " ',' " defaultHair = ' " . $defaultHair . " ',' " XPstrength = ' " . $XPstrength . " ',' " XPagility = ' " . $XPagility . " ',' " XPdexterity = ' " . $XPdexterity . " ',' " XPstamina = ' " . $XPstamina . " ',' " XPhealth = ' " . $XPhealth . " ',' "
XPintelligence = ' " . $XPintelligence . " ',' " XPcomprehension = ' " . $XPcomprehension . " ',' " XPpsyche = ' " . $XPpsyche . " ',' " XPmana = ' " . $XPmana . " ',' " hitPoints = ' " . $hitPoints . " ',' " hitPointsMax = ' " . $hitPointsMax . " ',' " basePhyAtk = ' " . $basePhyAtk . " ',' " basePhyDef = ' " . $basePhyDef . " ',' " baseShotAtk = ' " . $baseShotAtk . " ',' " baseMenAtk = ' " . $baseMenAtk . " ',' " baseMenDef = ' " . $baseMenDef . " ',' " speedMod = ' " . $speedMod . " ' WHERE gameName = ' " . $gameName . " ' AND playerPassword = ' " . $playerPassword . " ';";
///////////////////////////////////////////////////////////////////////////////
I can't seem to find the Syntax Error. Are ther any tutorials show mySQL updating at runtime for Unity??
Thanxs Christian
Answer by Adam Rademacher · Oct 04, 2010 at 06:12 AM
You are trading off your quotations too often. It should follow a pattern like this:
$query ="UPDATE players SET strength = ' " . $strength . " ', strengthMax = '" . $strengthMax .
(//)
speedMod = ' " . $speedMod . " ' " WHERE " gameName = ' " . $gameName . " ' AND playerPassword = ' " . $playerPassword . " '; " ;
In short, you ended up trying to assign the SQL column $strengthMax to a php variable "strength" (backwards from what it should be) in your sql command...if you fix all that syntax it should work appropriately. If you write your php in a program like Notepad++ or Dreamweaver, it should be much easier to see where your syntax errors are.
Thanxs I got rapidPHP and that helped see my syntax error. The final version of the function is on :
Answer by dyrwoolf · Jan 03, 2012 at 01:44 PM
If ur doing this make sure to clean the $varibles to prevent SQLInjections
Your answer
Follow this Question
Related Questions
Runtime communication with database 0 Answers
PHP MySQL - How to insert row of data 1 Answer
Export objects to a .3DS file at runtime 1 Answer
when i build my application i get ,some dll error 2 Answers
Database connection on PhPMyAdmin 1 Answer