hey guys i wanna ask a question about sending data to database to server using android app i am write script code by php like this .
<?php
$coonect=mysql_connect("myhost of the site ","root","");
if(!$coonect){
echo "Data_base error";
die(mysql_error());
}
?>
<?php
$username=$_POST['menu_name'];
$id=$_POST['id'];
$db_select=mysql_select_db("TableName");
if(!$db_select){
die(mysql_error());
echo" error";
}
$query= "INSERT INTO `DatabaseName`.`TableName` (
`name` ,
`id`
)
VALUES (
'{$username}', '{$id}'
); " ;
if($medo=mysql_query($query)){
header("localhost/filename");
exit;
}else{
echo"<p> Error</p>";
die(mysql_error());
}
?>
<?php
mysql_close($coonect);
?>
and the code in the action buuton in the android like this .
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mysite/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("menu_name", "any data"));
nameValuePairs.add(new BasicNameValuePair("id", "0345644"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
i dont change any thing in Androidmainfest file to establish the connection do i have to and if i should put something what isit ?!! but the apk work fine but it dosent work at all do i making something wrong in my code or i should put any permission in the Androidmainfest i dont know what's wrong ??? any Help pleas