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

    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"));
        //JSONObject json = jsonParser.makeHttpRequest(url_create_product,
          //      "POST", params);
        HttpClient httpClient= new DefaultHttpClient();

        HttpPost httpPost= new HttpPost("");
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response= httpClient.execute(httpPost);

        HttpEntity entity=response.getEntity();

    } catch(ClientProtocolException e) {
    } catch(IOException e){
        Log.e("Log Tag", "IOException");
    catch(Exception es){
        Log.e("Fallo de excep", "IOException");
    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);


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;



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