[HELP, PLEASE] Database used in the Construct 2

0 favourites
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Does anyone know any inform DATABASE , where I can use in the game developed with Construct 2 something how to Login and Show User Data logged ?!

    I tried mysql , mysqli and PHP using the PDO class, but got no success ... If anyone can help me or have a project and can provide , thank you enough!

    E- mail: cielholima gmail . com

  • Hi, see my reply on this topic :

    Don't hesitate to ask...

  • Saad Swad, I did a login system and can not access the menu ( the login layout is the User redirected to the menu ) , the problem is not that I can show User data saved in the bank ... use phpmyadmin while not do site to save the data on the server ...

    the only problem is just to show the data (score , name, image) of logged in User .

    I want to try and make available to others who may have the same doubts that I ... or if someone can share with me , thank you ... I implement the way I need ...

    excuse the bad English ... I speak Portuguese !! (laughs)

  • OK I understand now.

    To do that, you must create columns in your mysql table, for example, "Score", "Name" and "Image"...

    1. First, you must save into your database this information. You know how to do that... (else don't hesitate to ask...)

    2. Then, when user connects, your php file must return information with "echo" function. For example, to retrieve "score", your php file "SELECT Score FROM YourTable where USERNAME =$Username". And return this score with "echo".

    3. You have to do this operation with all your information BUT don't forget to separate all this data with a separator like " | " or " / " (or other string).

    4. Use ajax in Construct 2 to get all this data.

    So if score = 2 and username = Lima (in the database), Construct 2 retrieves " | 2 | Lima" (or other string if you choose another separator) from your php file after login...

    5. In your Construct 2, create two variables : "Score" and "Username" and use this events :

    6. Now you have all your data.

    NB : you can't register images in your database, you must upload your image to server and put the link into your database.

    Then use "Sprite : load from URL" action.

  • Hello , Saad Swad, is this part of the separator "|" I can not do in PHP ( I doubt ), I had to learn the basics to login. I can not do this tab in php, you can help me ( thank enough, boy )?! The following is what I did in login.php (See Fgures).

    Figure 1 - PHP code - Login

    Figure 2 - Database

    Figure 3 - Event in Construct 2

    Figure 4 - Login in the Game

    Figure 5 - Menu screen in game

    I understand that I have to use the " tokenat " but as use the old mysql , obsolete (I could not use the mysqli or PHP PDO class) ... do not know how to do tab using this version of mysql.

    Use Google Translate, so the English can is bad, sorry!

  • OK, let's improve some things.

    1. First, edit your php file :

    Check if $email already exists in your database, else if $email don't exists, echo " 0".

    If $email exists, check if $senha = " SELECT senha FROM login WHERE email='$email' "

    In php fie,

    $Separator =";";
    
    $Exist = "SELECT count(*) FROM login WHERE email='$email'";
    
    if ($Exist ==1)
    {
    
    if (" SELECT senha FROM login WHERE email='$email'" == $senha){
    
    $id = " SELECT id FROM login WHERE email='$email'" ; 
    $nome = " SELECT nome FROM login WHERE id='$id'" ;
    $sexo = " SELECT sexo FROM login WHERE id='$id'";
    $score = " SELECT score FROM login WHERE id='$id'" ;
    
    echo $nome. $separator . $sexo.$separator.$score
    };
    
    else if (" SELECT senha FROM login WHERE email='$email'" != $senha){
    echo "Error";
    }
    
    }
    
    else if($Exist ==0){
    
    echo "0";
    
    }
    
    [/code:eo015rhs]
    
    Now use this events in your Construct 2 app : 
    
    [img="http://enjoycss.com/bg-img/custom/22725-yvrjal.PNG"]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Saad Swad, When logar.php would look like?

    Or has something before connecting to the server?

    <?php
    	$email = $_GET['email'];
    	$senha = $_GET['senha'];
    
    	$Servidor = "localhost";
    	$Usuario = "root"; 
    	$Senha = ""; 
    	$Banco = "librauernplay";
    	$port = "3306";
    	
    	$Separator =";";
    	$Exist = "SELECT count(*) FROM login WHERE email='$email'";
    	if ($Exist ==1){
    		if (" SELECT senha FROM login WHERE email='$email'" == $senha){
    	
    		$id = " SELECT id FROM login WHERE email='$email'" ; 
    		$nome = " SELECT nome FROM login WHERE id='$id'" ;
    		$sexo = " SELECT sexo FROM login WHERE id='$id'";
    		$score = " SELECT score FROM login WHERE id='$id'" ;
    	
    		echo $nome. $separator . $sexo.$separator.$score;
    	
    		}else if (" SELECT senha FROM login WHERE email='$email'" != $senha){
    			echo "Error";
    		}
    	
    	}else if($Exist ==0){
    		echo "0";
    	}
    
    ?>[/code:1xg06wbz]
  • Don't forget the header and i recommand you to use POST Method.

    Attention! I don't have put "mysql_query" before every request but you have to do this...

  • Saad Swad, unfortunately I'm not getting ... You can make the file available to quoting the example (.capx and .php )?! I'm trying and I can not , I do not know what I've been doing!!

    So , i see better as you did and try to adapt the way I'm trying to do...

    my email :

  • Hello, Saad Swad, thank you very much. Now, when I test the Construct 2 he asked that I lowered the nwjs scirra.com/nwjs, at last, to my knowledge the NWJS Allows you to make Windows, Mac and Linux games with Construct 2. Anyway, my project is for the Android platform... Can you tell if it works on mobile devices or only on Desktop?

    Already, friend, gradeço and for your help!!

  • Lima Just change "Preview browser" in project propreties. This project works only on your PC, if you want use it on all plateforms you have to use a real php server and not wamp (or lamp or xamp...)

  • if you set

    $email = $_GET['email'];

    $senha = $_GET['senha'];

    check befor $_GET['theName'] is set with:

    if(isset($_GET['email'])){

    $email = $_GET['email'];

    }

    On a public server only a server log like [quote:3srptuut]

  • Saad Swad, yes, I did it, friend! Because to see that you used the NWJS thought I could have some difference with the android devices. Oh, you did the same example database that I posted? I tried to save user information and not saved ... I created the same page my-site , so possessed the same way...

    Sorry for asking too much!

  • BillAlex, excuse me, but did not understand!

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