How to send database to server with HttpPost in Android and check

I am using this code (which I copied from a tutorial) to send some information to the database in phpmyadmin. In the android app:

class UploadToDatabase extends AsyncTask<String, String, String> {
    List<NameValuePair> nameValuePairs= new ArrayList<NameValuePair>(1);
    //Metemos valores al database del Server

    @Override
    protected String doInBackground(String... params) {
        nameValuePairs.add(new BasicNameValuePair("_id", "2"));
        nameValuePairs.add(new BasicNameValuePair("COLUMNname", params[0]));
        nameValuePairs.add(new BasicNameValuePair("COLUMNimage", params[1]));
        nameValuePairs.add(new BasicNameValuePair("COLUMNsound", "tercero"));
    try{
        //JSONObject json = jsonParser.makeHttpRequest(url_create_product,
          //      "POST", params);
        HttpClient httpClient= new DefaultHttpClient();

        HttpPost httpPost= new HttpPost("http://192.168.1.35/AndroidFileUpload/UpData.php");
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response= httpClient.execute(httpPost);

        HttpEntity entity=response.getEntity();

        is=entity.getContent();
        //Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_LONG).show();
    } catch(ClientProtocolException e) {
        Log.e("ClientProtocol","Log_Tag");
        e.printStackTrace();
    } catch(IOException e){
        Log.e("Log Tag", "IOException");
        e.printStackTrace();
    }
    catch(Exception es){
        Log.e("Fallo de excep", "IOException");
        es.printStackTrace();
    }
    return null;
    }

And in the wampserver I use this php code:

<?
$DBhost = "localhost";
$DBuser = "xxxxx";
$DBpass = "xxxxx";
$DBName = "dbsound";
$table = "dbsound";
$conn = new mysqli_connect($DBhost,$DBuser,$DBpass,$DBName) 

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$_id=$_POST['_id'];
$COLUMNname=$_POST['COLUMNname'];
$COLUMNimage=$_POST['COLUMNimage'];
$COLUMNsound=$_POST['COLUMNsound'];

mysqli_select_db("$DBName") or die("Unable to select database $DBName");

$sqlquery = "INSERT INTO $table ("_id", "COLUMNname", "$COLUMNimage","COLUMNsound") VALUES(NULL,'$COLUMNname','$COLUMNimage','$COLUMNsound')";

$results = mysqli_query($sqlquery);

if ($conn->query($sqlquery) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sqlquery . "<br>" . $conn->error;
}

$conn->close();

?>

Where in the DBuser and DBpass I put the data of my phpmyadmin.
I don’t have any error, but it doesn’t appear anything in the database, so how can I know if the data were sent?


Source: wampserver

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.