How can I post data to php

Get help using Construct 2

Post » Fri Mar 10, 2017 2:52 am

Hi there,
I have a button for user to submit their name and score.
I want this data to be send to a php file which then will output to a text file.
How can I accomplish this?
Thanks
B
12
S
3
Posts: 15
Reputation: 734

Post » Sun Mar 12, 2017 10:04 am

@sebastiangohhy

You can do this with the AJAX plugin.

Just be aware that you need to use double quotes "" to escape text in Construct 2 when you are sending strings.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
45
S
11
G
20
Posts: 363
Reputation: 14,174

Post » Mon Mar 13, 2017 12:41 am

@cjbruce

Do I use PostToURL?

Is yes, is is like this?

Tag: "player1"
URL: "http://locahost/results.php?name=TextBox_player1.Text&score=totalscore_player1.Text"
Data: "name=URLEncode(TextBox_player1.Text)&score=URLEncode(totalscore_player1.Text)"
Method: "POST"
B
12
S
3
Posts: 15
Reputation: 734

Post » Mon Mar 13, 2017 1:39 am

@sebastiangohhy,

That looks good so far. Though it looks like you might have an error in the URL:

"http://locahost/results.php?name=""&TextBox_player1.Text&""&score=""&totalscore_player1.Text&""""

I would try a dummy page that echoes back or logs what you posted, but you are on the right track.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
45
S
11
G
20
Posts: 363
Reputation: 14,174

Post » Mon Mar 13, 2017 2:08 am

@cjbruce

URL: "http://localhost/results.php?name="""&URLEncode(TextBox_player1.Text)&"""&score="""&URLEncode(totalscore_player1.Text)&""""

Thanks for your help, i manage to modify your codes but just a tiny problem

the output is like this

name=%22testname%22&score=%22Score%3A%20500%22

is there a way to remove the %20 and %22
B
12
S
3
Posts: 15
Reputation: 734

Post » Mon Mar 13, 2017 3:07 am

@cjbruce

Its alright i found out. just needed to remove some extra "

"http://localhost/results.php?name="&URLEncode(TextBox_player1.Text)&"&score="&URLEncode(score_player1)&""
B
12
S
3
Posts: 15
Reputation: 734

Post » Mon Mar 13, 2017 9:44 am

@sebastiangohhy

Sorry -- I wasn't thinking clearly. Nice work!
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
45
S
11
G
20
Posts: 363
Reputation: 14,174

Post » Wed Mar 29, 2017 9:57 am

Hi even i am facing the same issue .... Can anybody give some tips ?
Last edited by vijkumar219 on Fri Mar 31, 2017 11:47 am, edited 6 times in total.
B
2
Posts: 2
Reputation: 154

Post » Fri Mar 31, 2017 1:52 am

@vijkumar219

Hi, what seems to be the problem
B
12
S
3
Posts: 15
Reputation: 734


Return to How do I....?

Who is online

Users browsing this forum: luck1210 and 11 guests