Rob,
The code i am using is just copied and pasted from your site. I finally got it to connect after some changes. I had to add an email column to my array and had to call
[php]
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
echo "Connected to MySQL
";
[/php]
before the if statement for it to connect and not give me the errors, also i had to take out the md5 in the string compare because my password is just a string and not encrypted.
[php]
<?php
define("DB\_DSN",'database');
define("DB\_HOST",'localhost');
define("DB\_USER",'admins');
define("DB\_PASS",'pass');
mysql\_connect(DB\_HOST, DB\_USER, DB\_PASS) or die(mysql\_error());
echo "Connected to MySQL
";
mysql\_select\_db(DB\_DSN) or die(mysql\_error());
echo "Connected to Database";
$link = mysql\_connect(DB\_HOST, DB\_USER, DB\_PASS) or die('Could not connect: ' . mysql\_error());
if(isset($\_GET)) {
$playername = base64\_decode($\_GET["playername"]);
$password = base64\_decode($\_GET["password"]);
$query = 'SELECT \* FROM players WHERE playername="' . mysql\_real\_escape\_string($playername) . '" or email="' . mysql\_real\_escape\_string($loginid) . '"';
$dbresult = mysql\_query($query, $link);
if (!$dbresult) {
//echo "query failed";
$result = array();
$result["result"] = 403;
$result["message"] = mysql\_error();
echo json\_encode($result);
mysql\_free\_result($dbresult);
exit;
}
$player = mysql\_fetch\_array($dbresult, MYSQL\_ASSOC);
if (strcmp($player["password"],$password) == 0) {
$result = array();
$result["result"] = 200;
$result["message"] = "Success";
$result["playername"] = $player["playername"];
$result["firstname"] = $player["firstname"];
$result["lastname"] = $player["lastname"];
$query = sprintf("UPDATE players SET lastlogin=NOW() WHERE id=%s;", $player["id"]);
$uresult = mysql\_query($query, $link);
if ($uresult) {
//code if your update failed. Doesn't really impact what we are doing. so do nothing.
}
echo json\_encode($result);
} else {
//echo "password mismatch";
$result = array();
$result["result"] = 403;
$result["message"] = "Forbidden";
echo json\_encode($result);
}
} else {
$result = array();
$result["result"] = 400;
$result["message"] = "Bad Request";
echo json\_encode($result);
}
exit;
[/php]
and here is the lua code im using
[lua]local mime = require("mime")
local json = require("json")
local playerName = "userid"
local password = "password"
local responseText = display.newText ("Nothing Yet", 0, 0, native.systemFont, 24)
responseText.x = 160; responseText.y = 75;
local URL = "http://server.com/scores.php?playername=" ..
mime.b64(playerName) .. "&password=" .. mime.b64(password)
local function loginCallback(event)
if ( event.isError ) then
print( "Network error!")
responseText.text = "Network Error!"
else
print ( "RESPONSE: " .. event.response )
local data = json.decode(event.response)
responseText.text = "RESPONSE: "..event.response
print (data.result)
-- do with data what you want...
end
return true
end
local function callreq ()
network.request( URL, "GET", loginCallback )
end
local button = display.newCircle (0, 0, 40)
button.x = 160; button.y = 240
button: addEventListener ("tap", callreq)[/lua]
the only problem i am having now is that when i try to get the data from the local data it is still nill and the response i get from the server is
RESPONSE: Connected to MySQL
Connected to Database{"result":200,"message":"Success","playername":"ryanr","firstname":"ryan","lastname":"robinson"}
but still no data, any suggestions oh guru of the databases [import]uid: 126161 topic\_id: 24922 reply\_id: 105173[/import]