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
48
S
14
G
24
Posts: 406
Reputation: 16,660

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
48
S
14
G
24
Posts: 406
Reputation: 16,660

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
48
S
14
G
24
Posts: 406
Reputation: 16,660

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

Post » Mon Oct 02, 2017 2:31 pm

Hi,
I was thinking of making something like this which I'm describing below step by step. You may call it as a pseudocode. :)
on the start of the game a request will be sent via ajax to a php page to check if the user is logged in or not on my website. Note: I have a wordpress website. If not logged in he/she we'll just set a variable to false in our project. If logged in we'll store the username in a text variable and show something like "welcome "X" bla bla..."

In the end of each game on my website I want to have submit highscore button. So, when somebody clicks on that it'll check if the login variable status is true or false. If true then we'll post the username and the highscore to a php page which will post the score to the database. If the variable is false the user will be prompted to login with fields or submit as guest. I'm not quite familiar with mysql and php and struggling with scripts . Can somebody help? Thanks in advance.
B
8
S
2
Posts: 25
Reputation: 554


Return to How do I....?

Who is online

Users browsing this forum: richcoz81 and 51 guests