PDA

View Full Version : how to store variables in Json format and then submit them to mysql by using PHP?



leihua
12 Dec 2009, 2:11 PM
Thank you!

mitchellsimoens
12 Dec 2009, 7:05 PM
look at PHP's json functions (http://us3.php.net/manual/en/ref.json.php). There is an encode and decode function.

Mike Robinson
14 Dec 2009, 7:07 AM
It bears repeating just what the process is, no matter what host-side language you are using:


ExtJS has its own server-side data structures. From time to time it wants to send a request to the host. It does so by, first, preparing a JavaScript "object" (which may contain other "objects," "arrays," and/or "scalars," ad nauseum.)
Now, in order to send that information to the host, ExtJS encodes it in an HTTP-transportable format, usually JSON. This information is then sent to the host as an ordinary-looking HTTP request (but one that is clearly labeled in its HTTP header as having JSON, not HTML or text, as its content-type).
The host, upon receipt of this data, must now decode it to produce a corresponding object in host-memory.
When the host is ready to send its response back, the host must once again encode its host-side data structure into JSON format for return to the client-side.
The client, now running its Ajax response-callback, decodes the host's response (back into a JavaScript object...) and reacts accordingly.


(Yes, I am glossing-over a few quibbling details.)

Notice also that there are two ways that the client can determine that a request "succeeded" or "failed," and so there are really three possible outcomes to consider:



Like any HTTP packet, the data received from the host contains a response-code such as "200 OK" or "404 Not Found" or maybe "500 Host Error." If this code is anything other than "200" (so to speak...), the request "failed." The problem is considered to be more-or-less a transmission error of some kind. ("Hello? Hello? This damn phone dropped me!" "No it didn't... their building just burned to the ground!" "Oh.")
If the response was received "200 OK," the host may or may not have successfully carried out the request. By convention, the host returns a "success: true" element if all is well, and "success: false" if for whatever reason it could not carry out the request (or declined to do so). ("Yeah, I heard ya loud and clear, but ... the answer is no!")