Mr.Aleks Posted May 11, 2015 Share Posted May 11, 2015 Hi! I've done a script in which i have encoded a table into JSON ans then i upload it into the mysql. The problem is that when i try to decode it with php, it doesnt work. Both scripts work fine Idk if its a problem of the Json-decode function for php or what... if someone knows how to do this.. Link to comment
xXMADEXx Posted May 12, 2015 Share Posted May 12, 2015 What exactly are you trying to do? It might just be able to be done with the PHP SDK. If it can't be done with the SDK, please post your Lua and PHP code. Link to comment
Mr.Aleks Posted May 12, 2015 Author Share Posted May 12, 2015 What I want to do is to get some information about the character when you create it, encode it into JSON ( because there are some arrays ) and upload it into a database. Once it's upload I want to get this information with php. Some of the code: Lua: ( the table and how I upload it to the mysql, but there are no errors with it. I mean, it uploads all right. ) -- the table is this one: players[source] = { ["id"] = data.id, ["user"] = data.user, ["pass"] = data.pass, ["nombre"] = nombre, ["apellido"] = apellido, ["edad"] = edad, ["altura"] = altura, ["peso"] = peso, ["skin"] = skin, ["sexo"] = sexo, ["dinero"] = 200, ["salud"] = 100, ["chaleco"] = 0, ["armas"] = amras, ["andar"] = style, ["estado"] = 1, ["pos"] = { ["x"]=64.80078125, ["y"]=-234.880859375, ["z"]=1.5723714828491, ["dimension"]=0, ["interior"]=0}, ["staff"] = { ["admin"] = 0, ["mod"] = 0, ["go"] = 0 } } --then I encode it with: info = toJSON(players[source]) --and I upload it with: local u = exports.sql:query_free( "UPDATE usuarios SET info = '%s' WHERE user ='%s'", info, data.user ) When I upload this I look in the database if it's well created and it's like this: [ { "altura": 170, "peso": 75, "nombre": "NAME", "chaleco": 0, "skin": 25, "edad": 22, "salud": 100, "apellido": "GARCIA", "user": "theuser", "id": 1, "pass": "thepass", "staff": { "mod": 0, "admin": 0, "go": 0 }, "sexo": "Hombre", "estado": 1, "armas": "NULL", "dinero": 200, "pos": { "y": -234.880859375, "x": 64.80078125, "z": 1.5723714828491211, "interior": 0, "dimension": 0 } } ] Then, when the player login in the website, I get the INFO: ... $id = mysqli_query($conex,'SELECT * FROM usuarios WHERE user ="'.mysqli_real_escape_string($conex, $user).'"'); if ($id) { while($row = mysqli_fetch_array($id, MYSQLI_ASSOC)) { $_SESSION['info'] = $row['info']; ... then, I call '$_SESSION['info']' in the file I want to get the information and I use it like this: $json1 = $_SESSION['info']; $json = json_decode($json1, true); $charname = "".$json->{'nombre'}."_".$json->{'nombre'}; but the '$json->{'nombre'}' and the $json->{'apellido'} dont return what they should return, and I don't know what's the problem. EDIT: I find the solution, php doesn't read the ''['' '']'' and I had to replace them. Now it gets the information. Tanks for everything. 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