Okay I am new to json and php so youll consider my question simple for you.
I am trying to insert data (name and id) from the app into the database . and I got this error
org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject
this is my php
<?php
$host='mysql12.000webhost.com';
$uname='a6901827_moudiz';
$pwd='**';
$db="a6901827_justed";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$id=$_REQUEST['id'];
$name=$_REQUEST['name'];
$sql = 'INSERT INTO samle '.
'(id ,name) '.
'VALUES ($id , $name )';
mysql_select_db('a6901827_justed');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
mysql_close($conn);
?>
and this is my code, if you think it needs improvement please don't hesitate.
public void postData(String valueIWantToSend) {
// Create a new HttpClient and Post Header
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id",id));
nameValuePairs.add(new BasicNameValuePair("name",name));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost =new HttpPost("http://justedhak.comlu.com/insert.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());
}