variables php on construct2???

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi everybody,

    I made a code in php for save some variable in php, the file is this:

    <?php

    $variable1= 100;

    $variable2 = $variable1;

    ?>

    I know this forum is not for php, but the problem is when I try to read the variable in construct2 with ajax because i don't understand the logic of construct 2.

    i need to set one variable in construct2 with a $variable2 of php file.

    the file:

    .capx

    .php file

    thank you so much, I really need to understand that, actually i spent 4 hours for that <img src="smileys/smiley19.gif" border="0" align="middle">

  • Hey man, i'm wainting for a new version of C2 to download, so i cannot open you capx, but i think this should get you going in the right direction:

    Your php could look something like this:

    <?php

    header('Access-Control-Allow-Origin: *');

    $variable1= 100;

    $variable2 = $variable1;

    echo $variable2;

    ?>

    the header is here to enable CORS, so you can test this from localhost, echo is actually returning the variable value when the ajax call is made.

    So in construct you can do:

    ----

    global variable "ConstructVar" = 0;

    on trigger -> AJAX request URL "http://mydomain.com/variable.php" (tag "php")

    On "php" completed -> set ConstructVar to Ajax.LastData

    ---

  • Try Construct 3

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

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

    so first of all you wanna change your AJAX Request to "http://yourserver.de/variable.php?variable2=" & variable2inConstruct.

    There is no need for the $ sign here and you need to specify your server adress.

    Second you need to output the content of your processed variable in php. I.g. " echo $variable2; "

    Should work.

    Btw. to post the content of your php file you need to serve it as txt. People wont be able to download your php file when its served as php.

  • In the How do I FAQ, section AJAX :

    How do I pull variables out of a PHP page using AJAX ? - LINK

    In the tutorials:

    AJAX example with Construct2; Online High Score Table (AJAX, PHP, MySQL).

  • In the How do I FAQ, section AJAX :

    How do I pull variables out of a PHP page using AJAX ? - LINK

    In the tutorials:

    AJAX example with Construct2; Online High Score Table (AJAX, PHP, MySQL).

    thask for the reply, I follow this example but doesn't work, I didn't understand the logic...

    now is working, but if I use the:

    <?php

    header('Access-Control-Allow-Origin: *');

    require 'gold.php';

    echo $gold;

    ?>

    the variable in construct 2 will be "NaN"

    gold.php is this:

    <?php

    header('Access-Control-Allow-Origin: *');

    require 'facebook_login.php';

    ///////////////////

                         ? if ( $loadspecific == "caricadati" ) {

            $query = "SELECT goldDB FROM tabletest WHERE UIDfacebook = $id";

            $result2 = mysql_query(mysql_real_escape_string($query)) or die (mysql_error());

            while($row = mysql_fetch_array($result2))

            {

                  ?//echo "\\";

                

                  ?$gold = "{$row['goldDB']}" ;

                  ?//echo $gold;

                  ?

                  ?//echo $_GET['gold'];

            }

            }else{

                //echo $result;

                }

    ?>

    I start to make a project with facebook... now my project save the data from facebook API in my database and load the single information in the database (gold.php)

    now my problem is load the variable in Construct2 because in php is working

    i'm thinking if the problem is "while($row = mysql_fetch_array" but the echo will be a single number like "1111", but Construct2 doesn't load the variable if I insert require 'facebook_login.php'; <img src="smileys/smiley19.gif" border="0" align="middle">

    the variable is from my database...

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