I am making like RPG game where user can login and save and load the data. I can login and save. But, when I want to load the data, I am having a trouble to load that.
I will post the necessary code only (PHP code (Load.php)):
<?PHP
$Username = $_POST['Username'];
$Location = $_POST['Location'];
$Gold = $_POST['Gold'];
$Level = $_POST['Level'];
$Attack = $_POST['Attack'];
$Defense = $_POST['Defense'];
$MagicDefense = $_POST['MagicDefense'];
$Evasion = $_POST['Evasion'];
$Health = $_POST['Health'];
$MaxHealth = $_POST['MaxHealth'];
$Mana = $_POST['Mana'];
$MaxMana = $_POST['MaxMana'];
$Exp = $_POST['Exp'];
$NextExp = $_POST['NextExp'];
$AcceptedChiefQuest = $_POST['AcceptedChiefQuest'];
$AddedChiefQuest = $_POST['AddedChiefQuest'];
$con = mysql_connect("SERVER_NAME","DATABASE_NAME","PASSWORD") or ("Cannot connect!" . mysql_error());
if (!$con)
die('Could not connect: ' . mysql_error());
mysql_select_db("DATABASE_NAME" , $con) or die ("Could not load the database" . mysql_error());
$check = mysql_query("SELECT * FROM Information WHERE `Username` = '".$Username."'");
$numrows = mysql_num_rows($check);
if ($numrows > 0)
{
while($row = mysql_fetch_assoc($check))
{
$Username = $row['Username'];
$Location = $row['Location'];
$Gold = $row['Gold'];
$Level = $row['Level'];
$Attack = $row['Attack'];
$Defense = $row['Defense'];
$MagicDefense = $row['MagicDefense'];
$Evasion = $row['Evasion'];
$Health = $row['Health'];
$MaxHealth = $row['MaxHealth'];
$Mana = $row['Mana'];
$MaxMana = $row['MaxMana'];
$Exp = $row['Exp'];
$NextExp = $row['NextExp'];
$AcceptedChiefQuest = $row['AcceptedChiefQuest'];
$AddedChiefQuest = $row['AddedChiefQuest'];
echo $Location;
}
die("Successfully Loaded!");
}
else
{
die ("Data does not exist!");
}
?>
And here where I access it by script in Unity (necessary code where the problem is):
IEnumerator LoadCoroutine(WWW _www)
{
yield return _www;
if (_www.error == null)
{
message = _www.text;
if (_www.text == "Successfully Loaded!")
{
// Below code from this line, never gets executed (if and else if statement)
// The `GameManager.CurrentLocation` appear as default value
if (_www.text == "Village")
{
GameManager.CurrentLocation = "Village";
GameManager.Loader = 1;
}
else if (_www.text == "Yein Plain")
{
GameManager.CurrentLocation = "Yein Plain";
GameManager.Loader = 4;
}
// Below code from this line will gets executed.
message = "Successfully Loaded.";
mainMenu = false;
yield return new WaitForSeconds(3);
Reset();
GameManager.LoadLevel("Loading Scene");
}
else if (_www.text == "Data does not exist!")
{
message = "Data does not exist";
clickedLoadGame = false;
}
else if (_www.text == "Saved data does not match!")
{
message = "Saved data does not match";
clickedLoadGame = false;
}
}
else
{
message = "Error while trying to connect to the server.\nMessage: " + _www.error;
clickedLoadGame = false;
}
}
When I Debug.Log
the message
, it appear like this: VillageSuccessfullyLoaded!
and it never appear like this Village
or Yein Plain
. Seems like the echo
and die
in PHP code gets combined together.
My question is, how to retrieve only the $Location
from php and not the other code? So it will return only Village
or Yein Plain
.
Really appreciate your answer!
Thank you very much