Salve, ho il seguente codice:
codice:
public void update()
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id",id));
nameValuePairs.add(new BasicNameValuePair("nome",nome));
nameValuePairs.add(new BasicNameValuePair("cognome",cognome));
try
{
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://www.nomesito.com/app/updatejd.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("pass 1", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(), "Invalid IP Address",
Toast.LENGTH_LONG).show();
}
try
{
BufferedReader reader = new BufferedReader
(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.e("pass 2", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 2", e.toString());
}
try
{
JSONObject json_data = new JSONObject(result);
code=(json_data.getInt("code"));
if(code==1)
{
Toast.makeText(getBaseContext(), "Update Successfully",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "Sorry, Try Again",
Toast.LENGTH_LONG).show();
}
}
catch(Exception e)
{
Log.e("Fail 3", e.toString());
}
}
però quando vado ammodificare dei dati contenuti nel DB mysql mi dice Invalid IP Address.
Come Mai? Il percorso è corretto http://www.nomesito.com/app/updatejd.php ho provato anche a mettere l'indirizzo ip del server al posto di www.nomesito.com ma da lo stesso errore.
il file update.php è il seguente:
codice:
<?php
$host='localhost';
$uname='pippo';
$pwd='123456';
$db="pippodb";
$con = mysql_connect($host,$uname,$pwd) or die("connection failed");
mysql_select_db($db,$con) or die("db selection failed");
$id=$_REQUEST['id'];
$nome=$_REQUEST['nome'];
$cognome=$_REQUEST['cognome'];
$flag['code']=0;
if($r=mysql_query("UPDATE utenti SET nome = '$nome', cognome = '$cognome' WHERE id ='$id'",$con))
{
$flag['code']=1;
}
print(json_encode($flag));
mysql_close($con);
?>
il problema è qui
codice:
catch(Exception e)
{
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(), "Invalid IP Address",
Toast.LENGTH_LONG).show();
}
Come posso risolverlo?
Grazie