How can I Post 2 variables at the same time

0 favourites
  • 4 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hey guys! I've spent my whole last night with scrawling around the forum, and didn't find a solution yet.

    I need a login system for my game. I've downloaded the Ajax_post plugin, got it working, but I've got a problem with it. I can't find the right syntax to post more than one variable at the same time.

    For example:

    POST:"var1="&user.texbox.Text&"var2="&pass.textbox.Text"
    

    outputs asdvar2=asd to the username column. (Which is quite logical, since I'm building a string)

    It works fine if someone sends just plain text as variables, like

    "var1=1&var2=2"

    , but it doesnt work in the way I'd need it.

    I've tried storing them in $_SESSIONs, but that didn't work out.

    (Yes, I am aware of the insecurity of this method, and I can assure you, that this is ONLY for testing and learning purposes.)

    o/t: The "Preview" function on creating/editing topics doesn't work for me (tested on Firefox/Chrome)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You are right you need to format it like var1=1&var2=2. The problem is it can be confusing mixing up & that means "add these strings together" and & which is part of an actual string.

    This expression:

    "var1=" & user.texbox.Text & "var2=" & pass.textbox.Text

    will result in a string like this:

    "var1=usertextvar2=passtext"

    Note the missing & because all your & mean "add strings".

    This should fix it:

    "var1=" & user.texbox.Text & "&var2=" & pass.textbox.Text

    Note the & inside a string meaning it is literally included in the text rather than adding strings together.

    Edit: just to clarify, don't use this for anything remotely serious! I know you know, but I just want to make sure I say it, because this is incredibly insecure :)

  • Ashley,

    In your example "var1=" & user.texbox.Text & "&var2=" & pass.textbox.Text

    Will the spacing after the & symbols effect the strings and the ajax data sent to the php page?

    For example is "http://localhost/login.php?var1=" & user.texbox.Text & "&var2=" & pass.textbox.Text

    the correct format?

    Or is "http://localhost/login.php?var1="&user.texbox.Text & "&var2=" &pass.textbox.Text

    the correct format?

  • levela, if Post variables via AJAX you must create a string that will look like "var1%var2" or any other character that won't be in contained by your variables, I often use * or ^, to create this string you can use: var1 & "*" & var2. In the postpack script(i suppose taht you use PHP), you must use the

    $string = $_POST['AJAX_TAG'] method to get the string and then :

    $anything = explode('*',$string) (that will create an array with your variables)

    $anything[0] = your first variable,

    $anything[1] = your second variable,

    if you need any help dont be afraid to ask. xD

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