How do I pull variables from a php page?

Get help using Construct 2

Post » Thu Oct 13, 2011 10:25 pm

Ok, I'm going to post what I have for my .capx for the saving variables to a database and the php for it.

FILE:
http://www.4shared.com/file/885mRUrE/ajaxsave.html

PHP:

<?php
include('connect.php');
if ($_GET['mode']=="save") {
$score = $_GET['score'];
$level = $_GET['level'];
mysql_select_db("p668534r_members", $con);
mysql_query("UPDATE ajax SET ajax_score = '$score', ajax_level = '$level'
WHERE username = 'b781rev'");
if (!mysql_query($sql,$con))
{ die('Error: ' . mysql_error()); }
mysql_close($con);
}
if ($_GET['mode']=="load") {
mysql_select_db("p668534r_members", $con);
$result = mysql_query("SELECT * FROM ajax WHERE username='b781rev'");
while($row = mysql_fetch_array($result))
{
echo $row['ajax_score']."|".$row['ajax_level']."|";
}
mysql_close($con);
}
?>

B
3
G
1
Posts: 50
Reputation: 725

Post » Fri Oct 14, 2011 3:32 pm

Did anyone find these examples useful?
B
3
G
1
Posts: 50
Reputation: 725

Post » Fri Oct 14, 2011 6:27 pm

Great example @b781rev! One thing though - on this line in the PHP:

[quote]mysql_query("UPDATE ajax SET ajax_score = '$score', ajax_level = '$level'
WHERE username = 'b781rev'");[/quote]

I don't know PHP very well, but it looks vulnerable to a SQL injection hack. If you request the AJAX URL with this for the score:

0';DROP DATABASE;

then you substitute that in to the SQL command and it wipes the database. You should be very careful about SQL injection - many, many sites have been hacked by that.Ashley2011-10-14 18:28:07
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Fri Oct 14, 2011 6:34 pm

Oh, I know. I just posted it as an example. I won't be running my site with queries like that.
B
3
G
1
Posts: 50
Reputation: 725

Post » Fri Oct 14, 2011 8:44 pm

Your posts are great, today after work hours I'll take a look. you can be sure I'm going to follow and suggesting questioner.'ll answer for here because I have enough reputation to do so in private. The text box and new buttons, put them through your work, because the moderators realize that it is essential for logon. A big hug from Chile.
B
7
S
2
G
4
Posts: 18
Reputation: 2,578

Post » Sat Oct 15, 2011 11:13 am

Here is a register example:

http://peepelz.com/index.php?game=ajaxregister
B
3
G
1
Posts: 50
Reputation: 725

Post » Sat Oct 15, 2011 7:29 pm

your posts are very good. I consider myself a beginner. would be great to publish a game where the user could register, login and logout. subsequently to login, you load the data from the previous game. It would also be very useful to teach us to create the database and everything related to store the records. Already very grateful and my respect for you.
B
7
S
2
G
4
Posts: 18
Reputation: 2,578

Post » Sat Oct 15, 2011 7:56 pm

[QUOTE=habiplay]would be great to publish a game where the user could register, login and logout. subsequently to login, you load the data from the previous game. It would also be very useful to teach us to create the database and everything related to store the records.[/QUOTE]

This all is out of the scope of C2's forum (once again).

This is webdeveloppement and you can find tons of examples and dediacted websites on the internet.
But this can't really be simplified and there are a lot of things to take in account/learn. Make a search in your own language for "mysql database" or "PHP login/registering".
Find a webdevelopment website in your own language this is where you'll get all you need. But be sure to look up for infos by yourself first, and not just wait for the infos to come at you.Kyatric2011-10-15 20:02:08
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Sat Oct 15, 2011 8:38 pm

[QUOTE=habiplay] your posts are very good. I consider myself a beginner. would be great to publish a game where the user could register, login and logout. subsequently to login, you load the data from the previous game. It would also be very useful to teach us to create the database and everything related to store the records. Already very grateful and my respect for you.[/QUOTE]

That is a full php dev production request. Again, either you check out the millions of tutorials out there related to php or maybe hire a professional developer to do this part.

On the plus side, C2 already takes care of the onerous task of trying to learn HMTL5. That alone can save about 6-8 months of development and research depending on one's expertise level.
B
18
S
8
G
7
Posts: 120
Reputation: 5,630

Post » Sat Oct 22, 2011 3:12 am

Too bad that this issue is no longer interested. But it remains a clear example for a user logs on and it loads the data from previous sessions. example, in an online casino credits are saved for a later session. if anyone knows how to do it please post an entire project. knowledge must come together, such as medicine and electronics come together to make a machine (eg, a dialysis machine). Neither the doctor nor the address on their own can do it. So hopefully someone will put together an expert in php expert C2 and can make the project possible.
B
7
S
2
G
4
Posts: 18
Reputation: 2,578

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: mercuryus and 16 guests