[HELP, PLEASE] Database used in the Construct 2

Get help using Construct 2

Post » Sun Jul 24, 2016 7:22 pm

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
B
8
S
3
G
1
Posts: 21
Reputation: 1,200

Post » Mon Jul 25, 2016 2:46 am

Hi, see my reply on this topic : viewtopic.php?f=147&t=179568

Don't hesitate to ask...
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Mon Jul 25, 2016 3:05 am

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)
B
8
S
3
G
1
Posts: 21
Reputation: 1,200

Post » Mon Jul 25, 2016 3:39 am

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 :
Image

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.
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Mon Jul 25, 2016 2:03 pm

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

Image
Figure 1 - PHP code - Login

Image
Figure 2 - Database

Image
Figure 3 - Event in Construct 2

Image
Figure 4 - Login in the Game

Image
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!
B
8
S
3
G
1
Posts: 21
Reputation: 1,200

Post » Mon Jul 25, 2016 3:39 pm

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,

Code: Select all
$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";

}




Now use this events in your Construct 2 app :

Image
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Mon Jul 25, 2016 5:43 pm

Saad Swad, When logar.php would look like?

Or has something before connecting to the server?

Code: Select all
<?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";
   }

?>
B
8
S
3
G
1
Posts: 21
Reputation: 1,200

Post » Mon Jul 25, 2016 5:48 pm

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...
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Mon Jul 25, 2016 7:21 pm

Message: Cyelho Lima can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
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 : [email protected]
B
8
S
3
G
1
Posts: 21
Reputation: 1,200

Post » Tue Jul 26, 2016 11:00 am

B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 62 guests