I am a complete noob and only started using servers, php, mysql and Stencyl last week. But anyone who reads these posts knows I have been trying to save game attributes to a server. I found a way. This is not to suggest it is the best way or the only way, or that people did not know. I am just putting it out there so some poor other person does not have to spend 5 days coming up with a way to do this.
This is just a brief outline of how to save Game Attributes to an online server. In order to achieve this you need 3 communication pathways.
1. The POST function available in Stencyl.
2. A php file on your server to receive the POST (with the GET or REQUEST function;
https://www.youtube.com/watch?v=IQmpTxKh9k8).
Example of code for a POST:
[/b]
<?php
include('connect-mysql.php');
$fname = $_REQUEST['fname']; (Notice how there is no submit button here, that it is easier to pass through for Stencyl)
$sqlinsert = "INSERT INTO People (firstname) VALUES ('$fname')";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "1 record added to the database";
?>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Insert Data into DB</h1>
<form method="REQUEST" action="Prosses.php">(Processes.php is usually called Index.php but just the php file receive the post)
<fieldset>
<legend>Score</legend>
<label>First Name: <input type="text" name="fname" /></label>
</fieldset>
<input type="submit" value="add new person" />
</form>
<?php
echo $newrecord
?>
</body>
</html>
[/b]
<?php
include('connect-mysql.php');
$fname = $_REQUEST[fname];
$sqlinsert = "INSERT INTO People (firstname) VALUES ('$fname')";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "1 record added to the database";
echo $fname
?>
PHP to MySql database
[/b]
3. Then the php should be set up to relay the data back to a mySql server (
https://www.youtube.com/watch?v=duMcPNbLGRI).
<?php
DEFINE ('DB_USER', 'YOURUSERNAME');
DEFINE ('DB_PSWD', 'YOURPASSWORD');
DEFINE ('DB_HOST', 'YOURHOST');
DEFINE ('DB_NAME', 'Score');
$dbcon = mysqli_connect (DB_HOST, DB_USER, DB_PSWD, DB_NAME);
if (!$dbcon) {
die('Fuck you fucker');
}
echo 'This is So annoying';
?>
Once you are in a position where you know that the php is connected to the server i.e., you can post or include information at the end of the .php url like ?fname=Warren and this information is sent to MySql and stored on the database, you are ready.
Final Part
Note in this demonstration I set the post to receive from the field name: fname and the table area in MySql was People, just like the Youtube clip.
Load the game to the server.
You need the subsequent code:
This is what Stencyl recommends
Now the code is sent in exactly the same way as the recommended method is suggested by Stencyl, it is just programmed in a way that makes the raw code the game attribute readable by the php file and transferable to MySql.
Hope this helps someone!