using WWW class

I’m constructing a url based on user input and defined variables which I’m passing to WWW in the attempt to have the user entered data added to a mysql database.

The url references a php file on the server which handles the db connection and data insertion. The constructed url seems fine, as if I use it in a browser the data is added correctly, but

data_post = WWW (url);

seems to do nothing, I’ve been over the highscores tut on the wiki and used similar logic (in fact have used the postscore function to try this) but the WWW call seems to not operate, it doesn’t exit with an error code.

Anyone else have any trouble with WWW?

thanks

WWW works find for me

you do a:

yield data_post;

afterwards, to wait for the web access to finish?

you should also try do put the output to the console, via

Debug.Log(data_post.data);

maybe your webserver reports php parse errors or something, which would not be interpreted as a connection error.

thanks for replying…

ye, I’m using a yield. This is basically the function that I’m calling from an OnGUI function once a user has entered text and hit a ‘submit’ button…

function postnote(name, note) {
   var note_url = insert_url + "mode=add&name=" + WWW.EscapeURL(name) + "&note_text=" + note + "&AUTHID=" + urlhash;
   print("url in function: " + note_url);    //confirm the constructed url
   note_post = WWW(note_url);
   yield note_post;
    if(note_post.error) {
        print("There was an error posting the data: " + note_post.error);
    }
    else 
    print("posted data");
}

I tried inserting the ‘Debug.Log(note_post.data)’, but it returns empty, that my be a clue though… not sure why it would be empty…

hm, looks fine for me.

have you tried to alter your php to just do a:

die(“hello world”);

on the first line?

just to make sure that its no error on the server side.

i personally never used a get request, i worked with the WWWForm class, look at the scripting reference, there are good examples. but i still don’t think that there is something wrong with your code on the unity side. You could also try EscapeURL on note, in case that is user input.

thanks, I tried the simple die php script on the server and WWW returns the string fine in unity, so the server seems ok.

So it seems that when the WWW call uses the full php string it is not returning anything. What is confusing me is that if I grab the url string that is constructed and paste it into a browser I get a result from the mysql db in the browser so I would assume that it should be returned to Unity.

Did you use WWWForm for retrieving data? I’ll look into that.

Update: I looked over the forming of the url and there was a problem, so it is returning the data to unity now. Half way there :slight_smile:

What’s odd is that the push data php isn’t working, and again, if I take the url and paste it into a browser it inserts data in mysql.

note_post.data won’t return anything in this case as it isn’t getting anything back from the php on insertion, though I guess I could insert an echo just for checking.