How can I Post 2 variables at the same time

Get help using Construct 2

Post » Thu May 17, 2012 8:56 am

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:
[/CODE]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 [CODE]"var1=1&var2=2"[/CODE], 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)levela2012-05-17 10:35:14
Posts: 1
Reputation: 277

Post » Thu May 17, 2012 12:03 pm

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:
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 :)Ashley2012-05-17 12:04:12
Scirra Founder
Posts: 24,376
Reputation: 193,842

Post » Thu Sep 27, 2012 8:49 pm


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?

Posts: 203
Reputation: 3,653

Post » Thu Sep 27, 2012 9:06 pm

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. xDwildmedia2012-09-27 21:16:00
Posts: 42
Reputation: 2,412

Return to How do I....?

Who is online

Users browsing this forum: JDebstup and 13 guests