Android + PHP + mySQL - Http post don't work -


i'm trying upload form data android java app (using android studio). i've created php file handle server side of upload, file using post method, receiving app form info, , upload data sql database.

so i'm trying enter data, async process work end connect, there no error @ nothing getting in sql table! i'm not getting tuple mysql server (to users table).i searched problem cant find. please me find bug or how can detect problem.

register.java code:

package com.example.user.social;  import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.util.log; import android.view.view; import android.view.window; import android.view.windowmanager; import android.widget.button; import android.widget.edittext; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.httpclient; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.message.basicnamevaluepair; import org.apache.http.util.entityutils;  import java.util.arraylist; import java.util.list;  public class register extends appcompatactivity {  button register; button back; edittext username; edittext password; edittext email; edittext name;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     requestwindowfeature(window.feature_no_title);     getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);     setcontentview(r.layout.activity_register);      register =      (button)     findviewbyid(r.id.register);         =      (button)     findviewbyid(r.id.back);     email    =      (edittext)   findviewbyid(r.id.edittext2);     name    =       (edittext)   findviewbyid(r.id.edittext);     username    =   (edittext)   findviewbyid(r.id.user);     password    =   (edittext)   findviewbyid(r.id.pass);      back.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {              startactivity(new intent(getapplicationcontext(),login.class));          }     });      register.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             string user = username.gettext().tostring().trim();             string pass = password.gettext().tostring().trim();             string emaill = email.gettext().tostring().trim();             string namee = name.gettext().tostring().trim();             new registerinserver().execute(user,pass,emaill,namee);         }     });   }  private class registerinserver extends asynctask<string,void,long> {     @override     protected long doinbackground(string... params) {          string username = params[0];         string email = params[2];         string name = params[3];         string password = params[1];          httpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost("http://idoazulay.byethost16.com/phpcode.php");          try {             // add data             list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(2);             namevaluepairs.add(new basicnamevaluepair("name", "name"));             namevaluepairs.add(new basicnamevaluepair("username", "username"));             namevaluepairs.add(new basicnamevaluepair("email", "idoazzz"));             namevaluepairs.add(new basicnamevaluepair("password", "87426088"));             httppost.setentity(new urlencodedformentity(namevaluepairs));              // execute http post request             httpresponse response = httpclient.execute(httppost);             string responsebody = entityutils.tostring(response.getentity());             log.d("hey",responsebody);          } catch (exception e) {             e.printstacktrace();              // todo auto-generated catch block         }         return null;      }      @override     protected void onpostexecute(long result) {     } } 

}

xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.example.user.social.register" android:background="#fff">  <linearlayout     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_alignparentright="true"     android:layout_alignparentend="true"     android:layout_below="@+id/user"     android:weightsum="1">      <edittext         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/user"         android:layout_alignparenttop="true"         android:layout_margintop="50dp"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true"         android:layout_alignparentright="true"         android:layout_alignparentend="true"         android:inputtype="text"         android:text="aaa"         android:textalignment="center"         android:textcolor="#9e9e9e"         android:layout_weight="0.15" />      <edittext         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/pass"         android:layout_alignparenttop="true"         android:layout_margintop="20dp"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true"         android:layout_alignparentright="true"         android:layout_alignparentend="true"         android:inputtype="text"         android:text="aaa"         android:textalignment="center"         android:textcolor="#9e9e9e"         android:layout_weight="0.15" />      <edittext         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/edittext"         android:layout_alignparenttop="true"         android:layout_margintop="20dp"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true"         android:layout_alignparentright="true"         android:layout_alignparentend="true"         android:inputtype="text"         android:text="aaa"         android:textalignment="center"         android:textcolor="#9e9e9e"         android:layout_weight="0.15"         android:layout_gravity="center_horizontal" />      <edittext         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/edittext2"         android:layout_alignparenttop="true"         android:layout_margintop="20dp"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true"         android:layout_alignparentright="true"         android:layout_alignparentend="true"         android:inputtype="text"         android:text="aaa"         android:textalignment="center"         android:textcolor="#9e9e9e"         android:layout_weight="0.15"         android:layout_gravity="center_horizontal" />      <button         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="חזרה"         android:id="@+id/back"         android:layout_gravity="center_horizontal"         android:layout_weight="0.05"         android:layout_margintop="20dp"         android:background="#58abff"         android:textcolor="#fff" />      <button         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="הרשמה"         android:id="@+id/register"         android:layout_gravity="center_horizontal"         android:layout_weight="0.05"         android:layout_margintop="0dp"         android:background="#2e8ece"         android:textcolor="#fff" />      <button         android:layout_width="match_parent"         android:layout_height="8dp"         android:id="@+id/button"         android:layout_gravity="center_horizontal"         android:layout_margintop="0dp"         android:background="#196ca3"         android:textcolor="#fff" />  </linearlayout> 

php:

<?php     $servername = "*****";     $username = "*****";     $password = "*****";     $dbname = "*****";      // create connection     $conn = new mysqli($servername, $username, $password, $dbname);     // check connection     if ($conn->connect_error) {         die("connection failed: " . $conn->connect_error);     }        $name=$_post['name'];     $email = $_post['username'];     $username = $_post['email'];     $password = $_post['password'];       $sql = "insert users (id,name,username,email,password)     values (default,'{$name}','{$username}','{$email}','{$password}')";      if ($conn->query($sql) === true) {         echo "new record created successfully";     } else {         echo "error: " . $sql . "<br>" . $conn->error;     }      $conn->close(); ?>  

sql users table:

id int(10) no
name varchar(15) no
username varchar(20) no
email varchar(40) no
password varchar(15) no

clarification: if access url computer chrome browser, adding null tupple user table, worked/ – ido azulay 12 mins ago

more question: way communicate server android app? (the php way)


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -