How can I post data to php

  • 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

  • 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.

  • 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"

  • 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.

  • 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

  • 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)&""

  • sebastiangohhy

    Sorry -- I wasn't thinking clearly. Nice work!

  • Hi even i am facing the same issue .... Can anybody give some tips ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • vijkumar219

    Hi, what seems to be the problem

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)