Hi!
I’ve been fighting with this for a while and I can’t get this done.
I have a SQLite database on an iPad where I insert records. That works OK.
When the user presses a button in the GUI, I loop through all the records and create a WWW object to upload each record’s information to a private server’s PHP page.
The PHP is extremely simple. It receives parameters through GET and inserts them to MySQL.
Now, the loop goes fine. All the WWW elements are created fine. I have debugged and I see each “http” request going fine.
The problem is, not all records are getting inserted. For instance, the first two are ignored… or the last 4…
There are no errors on Unity or on iPad console.
There are no errors on the PHP web page.
Inside Unity it seems to run perfectly. On iPad, some records are being left behind.
I have tried using the same WWW for each loop with yield until done.
Using one WWW for each loop, leaving the last WWW opened for ever.
Using one WWW but no yield, just waiting until the other one was done and the continuing.
Nothing worked.
But I can’t find the problem.
Is there anything I might be overlooking that might be causing this problem?
Thanks a lot in advance.
I can’t think of a reason why the unity side should deny it aside of you pushing more data through than you actually can through an url …
especially as GET is actually not meant for data upload and updating your online environment, POST and INSERT are the HTTP operations that are meant and should be used for it (especially cause get has size restrictions etc).
but you might want to look at the WWW.encodeurl etc functions to see if you potentially push through invalid characters (also ensure that you verify the data in the php, not that you by error push in data like ’ etc, cause that will potentially trash your db
Thanks,
I’ll check the encoding (although I’m using test text and they have no special chars) and WWWForm to see the POST method.
I’m really lost on this one so far.
The strange thing is I’m calling this URL:
var www = new WWW(“http://localhost/test.php?name=name1”);
That’s it. I do that with three names.
On Unity, all three names make it to the PHP.
On the iPad, the first two are left behind. Sometimes the last two. Sometimes the very last.
No errors at all.
EDIT: I’m not actually using localhost but a private IP
So it works with the very same build (universal binary) on iphone but not ipad?
I assume the iphone build is os4? (just so we can take into account os4 vs os3 changes on the NSURLConnection end which is used by unity iphone for WWW since 1.6)
It works on Unity in the Mac.
It doesn’t on iPad.
I’m using Unity 3.0b
My main problem is I can’t seem to reproduce the steps of the error.
Well desktop vs iDevice is a massive difference.
Already osx vs webplayer is a massive difference.
reason is that the networking used to do the WWW is platform depending:
Desktop: straight through socket as far as I know
Web: browser http pipeline
iDevice: As mentioned, this uses NSURLConnection
did you check what you are actually trying to send through there content wise?
The other issue is the iPad app instantly crashes (quits) if I try to use WWW.text or WWW.data to get a quick OK from the PHP page.
I’ll keep checking.
Thanks again for all your help.
thats very strange … sounds a lot like an issue with text encoding or something comparable (for example if you then print the text with gui.label and try to do so with non-western)
As Dreamora noted, carefully check the encoding.
I just finished an iPhone game whereby I had a problem using url data being posted. In the end I found it was because it had invalid character encoding in some of the characters in the string. It also seemed random because of how the data was drawn form a data source. It all looked fine in the Debug.Log window but had invalid bytes in the string that Debug.Log apparently could handle or ignored.
It might not be it, but it may help somebody that finds this thread with strange problems anyway.
Thanks for the tips.
I changed the way it works (made it some sort of asynchronic) and gave more time to each loop, and also encoded the result.
It seems to work fine so far.
If anything else comes up, I’ll post again.
I don’t know the solution, but sending a request for each row doesn’t seem like the thing to do. Why not combine them into one request?
Php can recieve arrays like this :
http://localhost/script.php?name[ ]=test1&name[ ]=test2
Or :
http://localhost/script.php?name[0]=test1&name[1]=test2
Might solve your problem, might not.
Basically because the URL has size limits, so that would present a problem for me, since the amount of information might exceed that limit.