ID:168971
 
I'm trying to make a basic save system, which saves Players into a Database located on a remote webserver.
Saving I have working, to an extent.

PHP:
<?
$dbhost="localhost";
$dbusername="tibbius_Tiberath";
$dbpassword="**********";
$dbname="tibbius_tibgame";

switch($HTTP_GET_VARS['action'])
{
default:
{
echo("Nothing to see here.");
echo("<META http-equiv=\"REFRESH\" content=\"1; url=http://www.tibbius.com\">");
break;
}

case 'save':
{
$keyname = $HTTP_GET_VARS["keyname"];
$name = $HTTP_GET_VARS["name"];
$gender = $HTTP_GET_VARS["gender"];
$race = $HTTP_GET_VARS["race"];
$gold = $HTTP_GET_VARS["gold"];
$connect = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname,$connect) or die ("Could not select database");
$result = mysql_query("INSERT INTO `playerbase` VALUES ('$keyname', '$name', '$gender', '$race', '$gold')",$connect);
break;
}
case 'load':
{
break;
}
}
?>


Thats the PHP script I have, and it does the job like it's ment to.

CREATE TABLE `playerbase` (
`keyname` text NOT NULL,
`name` text NOT NULL,
`gender` text NOT NULL,
`race` text NOT NULL,
`gold` text NOT NULL
) TYPE=MyISAM;


Thats the SQL script for my table. It works with the PHP aswell.

mob
var
Race = "Elf"
Gold = "5124"
Sex = "Male"

mob
verb
test()
world.Export("http://www.tibbius.com/player.php?action=save&keyname=[src.key]&name=[src.name]&gender=[src.Sex]&race=[src.Race]&gold=[src.Gold]")


And thats the actual DM code.

Now, my question falls down to.
A: How do I make a working PHP Loading Script in which case will send the data back to DM.
B: How do I make DM read the data.
C: For Saving, How do I make it override an already existing reccord for the users $keyname?

I would be greatful for any help i can get. Thanks.
A: How do I make a working PHP Loading Script in which case will send the data back to DM.

Load a script that posts the data in some fashion of: %name%Bob%name% then just parse the text in DM for the name. Use import I believe to get the data. Look into Volte's SiteParse demo.

B: How do I make DM read the data.

var/start = findtext(site,"%name%",1)+6
var/end = findtext(site,"%name%",start)
var/Thy_Name = copytext(site,start,end)

Something like I believe would work.

C: For Saving, How do I make it override an already existing reccord for the users $keyname?

Something to do with the way you set up the table. I don't remember though.

Hope this helps in some way.

-digitalRyno
Some points:
-Transmit a player's ckey rather than key so you don't get bit by unexpected characters.

-When posting data to be parsed by DM, use a params listing so all you need to do is use params2list() to get yourself an easy to work with list:
name=Bob&race=Elf&gold=200...
In response to tenkuu
i've made the change to ckey.
But the code above is as far as my PHP/MySQL/DM skills go.
So i'm finding it hard to understand what you mean here on in.