I am using the following code to post data to my server
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.kizikstudios.com/wltbo/new_score.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("name", "harry"));
nameValuePairs.add(new BasicNameValuePair("score", "12345"));
nameValuePairs.add(new BasicNameValuePair("pass", "***"));
HttpEntity entity = new UrlEncodedFormEntity(nameValuePairs);
httppost.addHeader(entity.getContentType());
httppost.setEntity(entity);
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String feedback = EntityUtils.toString(response.getEntity());
feedback.length();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
The server is receiving the post request but it says that the size is zero bytes, and my database never gets changed. In case it is needed here is the server side script.
<?
//****Made by: Jeroen den Haan***Alias's: jeroen84 / Jer'ul****
include_once ("_data.php");
$conn = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name,$conn);
if ($pass==$add_pass) {
if ($u_user==1) {
$sql3 = "SELECT name FROM $db_table ORDER BY name";
$result3 = mysql_query($sql3);
while($r = mysql_fetch_object($result3))
{
$tmp = "{$r->name}";
if ($name==$tmp) {
$n_exist=1;
}
}
if ($n_exist==1) {
$sql1 = "UPDATE $db_table SET score='$score' WHERE name=\"$name\"";
$result1 = mysql_query($sql1);
} else {
$sql1 = "INSERT INTO $db_table (name,score) VALUES (\"$name\",\"$score\")";
$result1 = mysql_query($sql1);
}
} else {
$sql1 = "INSERT INTO $db_table (name,score) VALUES (\"$name\",\"$score\")";
$result1 = mysql_query($sql1);
}
$sql2 = "SELECT id FROM $db_table ORDER BY score DESC";
$result2 = mysql_query($sql2);
$num = 1;
while($r = mysql_fetch_object($result2))
{
$result = mysql_db_query($db_name,"SELECT * from $db_table WHERE id='{$r->id}'");
$resultArray = mysql_fetch_array($result);
$did = $resultArray["id"];
$name = $resultArray["name"];
$score = $resultArray["score"];
if ($num>$sec_size) {
$sql3 = "DELETE FROM $db_table WHERE id='$did'";
$result3 = mysql_query($sql3);
}
$num++;
}
}
mysql_close ($conn);
?>
does anyone know why this would not work? Thank you in advance!
Where are your variables in php file that are capturing post values from other script? Can you var_dump() those variables to see if you are getting any post values to your php script?