First off, I just wanted to say, I am a rookie with PHP so take it all with a grain of salt.
I think got something to do with the connection between JavaScript and PHP, It doesnt comply with the ISO-9001 standards. Therefor I advise you to rewrite your whole script in jQuery or AJAX.
The ?undefined stands for:
[*] Something that lacks definition
[*] In mathematics, something which lacks well-definition
[*] In calculus, an indeterminate form
[*] Undefined citizenship, a term used sometimes for statelessness
[*] Undefined behavior of some software
[*] Undefined value, a condition in programming
[*] A variable lacking Initialization (programming)
[*] An unavailable linker symbol (function, or global variable), see dynamic linker
I hope this list can help you on your journey to a working script. (You might need to access your variables in their full form.)