xyzii Posted December 17, 2016 Share Posted December 17, 2016 (edited) So I'm making a vehicle system with SQL, it's finished but the thing is that when I buy the vehicle, move and hide it then spawn it, it does what it's supposed to do, but the second time I do it, it doesn't work anymore. To clarify, my account name is addaccount. I believe it has something to do with the Affected rows: 0. 2016-12-17 23:35:22.292: [script] SUCCESS: Affected rows:0 [Query:UPDATE addaccount SET veh='Buccaneer', x=2140.720703, y=-1117.307617, z=24.937660, rot=264.001465, bp=5000, ups='asd', plate='90QK LL8', hp=1000, fuel=0, lock=0, r=255, g=255, b=255 WHERE num='75834'] Here's the code of the hide function function hideVehicle(player) if (isGuestAccount(player.account)) then return end if (not isElement(vehs[player])) then return end local num = vehs[player]:getData("num") local veh = vehs[player].name local xe, ye, ze = getElementPosition(vehs[player]) local xr, yr, rot = getElementRotation(vehs[player]) local r, g, b = getVehicleColor(vehs[player], true) local lock = getElementData(vehs[player], "lock") local ups = getVehicleUpgrades(vehs[player]) outputChatBox(num..veh..xe..ye..ze..rot..r..g..b..lock) local query = "UPDATE "..player.account.name.." SET veh=?, x=?, y=?, z=?, rot=?, bp=?, ups=?, plate=?, hp=?, fuel=?, lock=?, r=?, g=?, b=? WHERE num=?" dbExec(con, query, veh, xe, ye, ze, rot, 5000, "asd", vehs[player].plateText, vehs[player].health, vehs[player]:getData("fuel"), lock, r, g, b, num) destroyElement(vehs[player]) vehs[player] = nil return true end addCommandHandler("hide", hideVehicle) Edited December 17, 2016 by xyzii Link to comment
Bonsai Posted December 17, 2016 Share Posted December 17, 2016 The table in the database is named like the players account? Else it needs to be in there WHERE condition. Link to comment
xyzii Posted December 17, 2016 Author Share Posted December 17, 2016 Yes the table is the player's account Link to comment
LoPollo Posted December 18, 2016 Share Posted December 18, 2016 On 17/12/2016 at 11:04 PM, Bonsai said: Else it needs to be in there WHERE condition. num=? > ? is the variable num with the value of vehs[player]:getData("num") Output/debug that variable and check it isn't returning false. Link to comment
xyzii Posted December 18, 2016 Author Share Posted December 18, 2016 It returns as the number it's supposed to be Link to comment
LoPollo Posted December 19, 2016 Share Posted December 19, 2016 Then the only thing that's left is the table itself. Did you try using a graphical viewer to check if records have the field num as it's supposed to? But since you don't change this field and the first time it's working then we can delete this from the list. Still see if the table has the correct values that you get from the script. Note: It is usually good practice to surround table and column names with backticks (`) in case they contain spaces or SQL keywords (and therefore cause syntax errors). This is especially true when using variables for table and column names, as potential problems may not be apparent when the script is first written. Some vehicle have spaces in their name, and the plate can have spaces too. Other than this i'm out of ideas Link to comment
xyzii Posted December 20, 2016 Author Share Posted December 20, 2016 I got it to work when I used tonumber(num), but thanks for your help anyway, you taught me a bit about SQL that I didn't know Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now