- Home /
www php doesnt receive whole string
im making a inventory system that logs its items to a datbase server. i have most of it working but the problem im having is that i send a string of 200 chars to my php script, but when i echo it in my php script it only give me the first 24 characters of the string.
what i send:
{"name":"inventory", "array":[ {"ItemName":"White Shirt", "ItemID":"1", "ItemDesc":"A white T-shirt", "ItemPower":"0", "ItemSpeed":"0"}, {"ItemName":"Amulter of Prayers", "ItemID":"0", "ItemDesc":"An amulet enchanted by prayers", "ItemPower":"2", "ItemSpeed":"0"}, {"ItemName":"Brown Feather", "ItemID":"2", "ItemDesc":"A Brown Feather", "ItemPower":"0", "ItemSpeed":"0"}, {"ItemName":"Yellow Light", "ItemID":"3", "ItemDesc":"A Yellow Light", "ItemPower":"0", "ItemSpeed":"0"}, {"ItemName":"Large Health Potion", "ItemID":"4", "ItemDesc":"A Large Health Potion", "ItemPower":"0", "ItemSpeed":"0"}, {"ItemName":"Medium Power Potion", "ItemID":"5", "ItemDesc":"A medium Power Potion", "ItemPower":"0", "ItemSpeed":"0"}]}
what my php script echo's:
{\"name\":\"inventory\",
this is my php code:
<?php
$db = mysql_connect('localhost', 'name', 'pass')
or die ('could not connect: ' . mysql_error());
mysql_select_db('DB') or die('could not select database');
// Strings must be escaped to prevent SQL injection attack.
$username = mysql_real_escape_string($_GET['username'], $db);
$inventory = mysql_real_escape_string($_GET['inventory'], $db);
$hash = $_GET['key'];
$secretKey="mySecretKey2"; # Change this value to match the value stored in the client javascript below
$real_hash = md5($username . $inventory . $secretKey);
echo $inventory;
//if($real_hash == $hash) {
$query = "INSERT into users values (0, '$username',NULL, 0,'$inventory');";
$result = mysql_query($query) or die ('Query failed: ' .mysql_error());
echo "SubmittedScore";
// }
?>
and this is my c# function:
IEnumerator handleSubmit()
{
gamemanager = GameObject.FindGameObjectWithTag ("gamemanager");
string name = gamemanager.GetComponent<LoggedInUser>().loggedInUser;
string key = Md5Sum(name + myInventory + secretKey);
string submit_url = submitURL + "username=" + WWW.EscapeURL(name) + "&key=" + key + "&inventory=" + myInventory ;
WWW submitReader = new WWW(submit_url);
yield return submitReader;
Debug.Log (submitReader.text);
}
so my question is how do i get my php script to get the full string?
Answer by Victory Dan Greene · Jan 07, 2015 at 04:06 PM
At first blush, it looks like you may have forgotten to url-encode the "myInventory" component of the url you're hitting—so its $_GET value only includes the JSON up to the first word space (which isn't allowed in a url).
ah right dude thanks.
do you maybe know what mysql_query i use to insert the string into the table of the user i send with the url post?
I'm not sure what your database schema is like, but isn't the line...
$query = "INSERT into users values (0, '$username',NULL, 0,'$inventory');";
...isn't that what you want to run to add the inventory to the table?
If i run that query it just creates a new entry with the same username but it doenst add the new inventory to the user is give with it.
It doesnt need to create a new user. It needs to add inventory to the current user wich i send to the php
If you're sure there is already a row for the current user, you probably want to obtain that row's id somehow and use an UPDATE statement like
"UPDATE users SET inventory = '$inventory' WHERE id = '$id' ;"
Your answer
Follow this Question
Related Questions
PHP POST through $_REQUEST with WEBBUILD 1 Answer
Is it possible to call a Javascript code on local server from Unity? (Google Chart API involved) 2 Answers
How do I know that php server is available? (C# script) 1 Answer
Unity C# I need my PHP page to Run (on the Server) Without me Getting or Sending Info 0 Answers
www.text + php + c# issue 2 Answers