Let me explain it better. i have made an app which has 3 fields. I want to insert these three fields into database. I'm getting 'data successfully inserted' message in toast but values are not getting inserted in database. Even i don't have any errors.. Thanku!
My php file:
<?php
//Define your host here.
$hostname = "localhost";
//Define your database username here.
$username = "root";
//Define your database password here.
$password = "root";
//Define your database name here.
$dbname = "SCPL";
$con = mysqli_connect($hostname,$username,$password,$dbname);
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$Sql_Query = "insert into scpl (name,email,website) values ('$name','$email','$website')";
if(mysqli_query($con,$Sql_Query)){
echo 'Data Inserted Successfully';
}
else{
echo 'Try Again';
}
mysqli_close($con);
?>
This is my mainactivity.java class:
public class MainActivity extends Activity {
EditText editTextName, editTextEmail, editTextWebsite;
String GetName, GetEmail, GetWebsite;
Button buttonSubmit ;
String DataParseUrl = "http://192.168.2.6/androids/insert.php";
//String HttpURL = "http://192.168.2.26/Android_php/gps_tracker/insert.php";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextName = (EditText)findViewById(R.id.editText1);
editTextEmail = (EditText)findViewById(R.id.editText2);
editTextWebsite = (EditText)findViewById(R.id.editText3);
buttonSubmit = (Button)findViewById(R.id.button1);
buttonSubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
GetDataFromEditText();
SendDataToServer(GetName, GetEmail, GetWebsite);
}
});
}
public void GetDataFromEditText(){
GetName = editTextName.getText().toString();
GetEmail = editTextEmail.getText().toString();
GetWebsite = editTextWebsite.getText().toString();
}
public void SendDataToServer(final String name, final String email, final String website){
class SendPostReqAsyncTask extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
String QuickName = name ;
String QuickEmail = email ;
String QuickWebsite = website;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", QuickName));
nameValuePairs.add(new BasicNameValuePair("email", QuickEmail));
nameValuePairs.add(new BasicNameValuePair("website", QuickWebsite));
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(DataParseUrl);
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return "";
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Toast.makeText(MainActivity.this, "Data Submit Successfully", Toast.LENGTH_LONG).show();
}
}
SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
sendPostReqAsyncTask.execute(name, email,website);
}
}
i haven't found any errors/mistakes, try changing your URL/ip address to:
Use 10.0.2.2 for default AVD and 10.0.3.2 for genymotion.
Try using $_REQUEST instead of $_POST and check the response from the server first before showing the success message in your onPostExecute function like #MJM suggested.
I had similar problems with my API and android app when I was sending the data as POST request, the only way to get the submitted data was with $_REQUEST
Related
I am trying to get the response code for the HttpReponse.
I have changed the method for getting the response but it is not working.
Before I used this try & catch:
(url is parameter for function)
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost method = new HttpPost(url);
if (params != null) {
method.setEntity(new UrlEncodedFormEntity(params));
}
HttpResponse response = httpclient .execute(method);
InputStream inputStream = response.getEntity().getContent();
String result = convertInputStreamToString(inputStream);
return result;
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
But this code gave me a runtime error in HttpResponse response = httpclient .execute(method);
So I changed my code:
public class RegisterActivity extends Activity {
String username;
String password;
InputStream is = null;
String result = null;
String line = null;
int code;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
final EditText usernamefield = (EditText) findViewById(R.id.username_reg);
final EditText passwordfield = (EditText) findViewById(R.id.password_reg);
Button reg_btn = (Button) findViewById(R.id.reg_btn);
reg_btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
username = usernamefield.getText().toString();
password = passwordfield.getText().toString();
insert();
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", usernamefield.getText().toString()));
params.add(new BasicNameValuePair("password", passwordfield.getText().toString()));
params.add(new BasicNameValuePair("action", "insert"));
}
});
}
public void insert()
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("action", "insert"));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.10/ferdos/service.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());
}
try
{
JSONObject json_data = new JSONObject(result);
code = (json_data.getInt("code"));
if (code == 1)
{
Toast.makeText(getBaseContext(), "Inserted Successfully",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "Sorry, Try Again",
Toast.LENGTH_LONG).show();
}
}
catch (Exception e)
{
Log.e("Fail 3", e.toString());
}
}}
Please help me with this code to solve my problem.
Thats what Google says.
To avoid creating an unresponsive UI, don't perform network operations on the UI thread. By default, Android 3.0 (API level 11) and higher requires you to perform network operations on a thread other than the main UI thread; if you don't, a NetworkOnMainThreadException is thrown.
You need to execute your HTTP requests in separate thread. This can be done in a AsyncTask.
In your case you need to update UI after the downloading is finished. Use a listener to notify the UI thread
public interface ResultsListener {
public void onResultsSucceeded(String result);
}
This is an example from Google developers guide. I edited it and it calls the listener when the result is finished.
private class HttpRequestTask extends AsyncTask<URL, Integer, String> {
public void setOnResultsListener(ResultsListener listener) {
this.listener = listener;
}
protected String doInBackground(URL... urls) {
int count = urls.length;
for (int i = 0; i < count; i++) {
String httpResult = // Do your HTTP requests here
// Escape early if cancel() is called
if (isCancelled()) break;
}
return httpResult;
}
// use this method if you need to show the progress (eg. in a progress bar in your UI)
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
// this method is called after the download finished.
protected void onPostExecute(String result) {
showDialog("Downloaded " + result);
listener.onResultsSucceded(result);
}
}
Now you can execute the task by calling new HttpRequestTask().execute(url) in your Activity. Your activity needs to implement the ResultsListener. Inside the onResultsSucceeded method you can update your UI elements.
You see, you can use the AsyncTask in your example pretty well. You just need some reformatting of your code.
I use AsyncTask but dont working again
please check my code
public class RegisterActivity extends Activity {
EditText editusername;
EditText editpassword;
String username;
String password;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
editusername = (EditText) findViewById(R.id.username_reg);
editpassword = (EditText) findViewById(R.id.password_reg);
Button reg_btn = (Button) findViewById(R.id.reg_btn);
reg_btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
username = editusername.getText().toString();
password = editpassword.getText().toString();
new RegisterAsyncTask().execute();
}
});
}
class RegisterAsyncTask extends AsyncTask<Void, Void, Boolean> {
private void postData(String username, String password) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("myurl");
try {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("action", "insert"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
}
catch (Exception e)
{
Log.e("log_tag", "Error: " + e.toString());
}
}
#Override
protected Boolean doInBackground(Void... params) {
postData(username, password);
return null;
}
}}
I‘m trying to create an android app where the data is filtered and fetched from a server. For that I want to upload a string to the script insert it into the query and fetch the rows that contain the given parameter. In my code I set a fixed string to test it, but the problem is that it doesn‘t return anything, maybe you can see my fault.
The table in the database only contains rows of single letters
My script:
<?php
include 'DatabaseConfig.php';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$var = $_POST['name'];
$query = "SELECT * FROM TestTable WHERE name = '$var'";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($result)) {
$array[] = $row;
}
header('Content-Type:Application/json');
echo json_encode($array);
mysqli_close($conn);
?>
My code:
public class MainActivity extends AppCompatActivity {
List<GetDataAdapter> GetDataAdapter1;
RecyclerView recyclerView;
RecyclerView.LayoutManager recyclerViewlayoutManager;
RecyclerView.Adapter recyclerViewadapter;
ProgressBar progressBar;
String a = "a";
String ServerURL = "https://abcde.com/test.php";
EditText name;
Button button;
String TempName;
String JSON_ID = "id";
String JSON_NAME = "name";
JsonArrayRequest jsonArrayRequest;
com.android.volley.RequestQueue requestQueue;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GetDataAdapter1 = new ArrayList<>();
recyclerView = (RecyclerView) findViewById(R.id.recyclerView1);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
button = (Button) findViewById(R.id.button);
recyclerView.setHasFixedSize(true);
recyclerViewlayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(recyclerViewlayoutManager);
name = (EditText) findViewById(R.id.editText);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
GetData();
InsertData(a);
JSON_DATA_WEB_CALL();
}
});
}
public void GetData() {
TempName = name.getText().toString();
}
public void InsertData(final String a) {
class SendPostReqAsyncTask extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
String NameHolder = a;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", NameHolder));
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(ServerURL);
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return "Data Inserted Successfully";
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Toast.makeText(MainActivity.this, "Data Submit Successfully", Toast.LENGTH_LONG).show();
}
}
SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
sendPostReqAsyncTask.execute(a);
}
public void JSON_DATA_WEB_CALL() {
jsonArrayRequest = new JsonArrayRequest(ServerURL,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
progressBar.setVisibility(View.GONE);
JSON_PARSE_DATA_AFTER_WEBCALL(response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonArrayRequest);
}
public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array) {
for (int i = 0; i < array.length(); i++) {
GetDataAdapter GetDataAdapter2 = new GetDataAdapter();
JSONObject json = null;
try {
json = array.getJSONObject(i);
GetDataAdapter2.setId(json.getInt(JSON_ID));
GetDataAdapter2.setName(json.getString(JSON_NAME));
} catch (JSONException e) {
e.printStackTrace();
}
GetDataAdapter1.add(GetDataAdapter2);
}
recyclerViewadapter = new RecyclerViewAdapter(GetDataAdapter1, this);
recyclerView.setAdapter(recyclerViewadapter);
}
}
You're doing wrong when you are receiving the data from databse like
while ($row = mysqli_fetch_assoc($result)) {
// Now do like, name of the field in your database put inside the $row['here'];
echo $row['username'];
echo $row['password'];
}
Now that should work;
Thank's
So I have a ProfileActivity where I pass the user's details to EditProfileActivity.. the passed values are placed correctly on their specified edittexts. But whenever I change the values in the edittexts and clicked the save button..the values on the database are not modified..Can you please help me
package com.example.androidproject;
public class EditProfileActivity extends Activity {
Button Save, Delete;
EditText tname,tusername, tpassword, tpassword2, tbio;
TextView uname;
User u = new User();
String editfullname,editpw,editpw2,editbio,getuname;
String fn,b,pw,pw2;
TextView tv1,tv2,tv3;
String getfn,getpw,getbio;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editprofile);
Save = (Button) findViewById(R.id.buttonsignup);
Delete = (Button) findViewById(R.id.button1);
tname = (EditText) findViewById(R.id.txtfullname);
tusername = (EditText) findViewById(R.id.txtun);
tpassword = (EditText) findViewById(R.id.txtpw);
tpassword2 = (EditText) findViewById(R.id.txtpw2);
tbio = (EditText) findViewById(R.id.txtbio);
uname = (TextView) findViewById(R.id.getusername);
tv1 = (TextView) findViewById(R.id.textView2);
tv2 = (TextView) findViewById(R.id.textView3);
tv3 = (TextView) findViewById(R.id.textView4);
Intent intent = getIntent();
u.SetUsername(intent.getStringExtra(u.username()));
editfullname = (intent.getStringExtra("Fullname"));
editbio = (intent.getStringExtra("Bio"));
editpw = (intent.getStringExtra("Password"));
editpw2 = (intent.getStringExtra("Password2"));
uname.setText(u.getUsername());
tname.setText(editfullname);
tpassword.setText(editpw);
tpassword2.setText(editpw2);
tbio.setText(editbio);
getuname = u.username().toString();
Save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
fn = tname.getText().toString();
pw = tpassword.getText().toString();
b = tbio.getText().toString();
tv1.setText(fn); //i displayed to textviews the NEW values inputted from the edittexts.
tv2.setText(pw);
tv3.setText(b);
getfn = tv1.getText().toString(); //i put these to the namevalupairs in my asynctask
getpw = tv2.getText().toString();
getbio = tv3.getText().toString();
new SaveDataTask().execute();
}
});
}
class SaveDataTask extends AsyncTask<String, String, Void> {
protected void onPreExecute() {
}
#Override
protected Void doInBackground(String... params) {
byte[] data;
HttpPost httppost;
StringBuffer buffer = null;
HttpResponse response;
HttpClient httpclient;
InputStream inputStream;
List<NameValuePair> nameValuePairs;
nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("Fullname", getfn.trim()));
nameValuePairs.add(new BasicNameValuePair("Username", getuname));
nameValuePairs.add(new BasicNameValuePair("Password", getpw.trim()));
nameValuePairs.add(new BasicNameValuePair("Bio", getbio.trim()));
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://192.168.1.6/webservices/mycontroller/updateuser.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data)) ) {
buffer.append(new String(data, 0, len));
}
//name= buffer.toString();
inputStream.close();
runOnUiThread(new Runnable(){
public void run() {
Toast.makeText(EditProfileActivity.this, "UPDATED", Toast.LENGTH_LONG).show();
}
});
}
catch (Exception e) {
Toast.makeText(EditProfileActivity.this, "error" + e.toString(), Toast.LENGTH_LONG).show();
}
return null;
}
}
}
Here is my php code for update:
<?php
mysql_connect("localhost","root","");
mysql_select_db("poetrydb");
$Fullname = $_POST['Fullname'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Bio = $_POST['Bio'];
$query_insert = "UPDATE account SET FullName ='$Fullname', Bio= '$Bio', Password ='$Password' WHERE Username ='$Username'";
mysql_query($query_insert) or die(mysql_error());
echo "UPDATED";
?>
You need to update the values on click event otherwise you will always be passing the same value that you received in onCreate
Save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// fetch the updated values from edittext and
// store them in string references
fn = tname.getText().toString();
getuname = u.username().toString();
pw = tpassword.getText().toString();
b = tbio.getText().toString();
new SaveDataTask().execute();
I'm creating a Android PHP MySQL Login app that will check the username and password from MySQL server. I get the tutorial from here
I have checked the name and password in MySQL and it matches with what user type, but I still unable to go to HomePage activity as it displays Invalid username or password.
private void login(final String username, final String password) {
class LoginAsync extends AsyncTask<String, Void, String> {
private Dialog loadingDialog;
#Override
protected void onPreExecute() {
super.onPreExecute();
loadingDialog = ProgressDialog.show(MainActivity.this, "Please wait", "Loading...");
}
#Override
protected String doInBackground(String... params) {
InputStream is = null;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
String result = null;
try{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(
"http://192.168.1.7:80/Android/CRUD/login.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
#Override
protected void onPostExecute(String result){
String s = result.trim();
loadingDialog.dismiss();
if(s.equalsIgnoreCase("success")){
Intent intent = new Intent(MainActivity.this, HomePage.class);
//intent.putExtra(USER_NAME, username);
finish();
startActivity(intent);
}else {
Toast.makeText(getApplicationContext(), "Invalid User Name or Password", Toast.LENGTH_LONG).show();
}
}
}
LoginAsync la = new LoginAsync();
la.execute(username, password);
}
login.php
<? php
require_once("dbConnect.php");
$con = mysqli_connect(HOST,USER,PASS,DB);
$username = $_POST['name'];
$password = $_POST['password'];
$sql = "select * from users where name='$username' and password='$password'";
$res = mysqli_query($con,$sql);
$check = mysqli_fetch_array($res);
if(isset($check)){
echo 'success';
}else{
echo 'failure';
}
mysqli_close($con);
?>
$username = $_POST['name'];
change to this one :
$username = $_POST['username'];
check response in Log first..
protected void onPostExecute(String result){
String s = result.trim();
Log.d("response: ", s);
}
I'm working on an application that stores user inputs into the database table via PHP API but i get an error message from the PHP code to the LogCat. Any advice would be greatly appreciated.
D/Create Response(284): {"message":"Required field(s) is missing","success":0}
PHP API
<?php
// array for JSON response
$response = array();
// check for the fields
if (isset($_POST['title']) && isset($_POST['request_date']) && isset($_POST['reqEndDate']) && isset($_POST['reason']) && isset($_POST['requestor']) && isset($_POST['status']) && isset($_POST['submitDate']) && isset($_POST['explanation']) && isset($_POST['hours']) && isset($_POST['id'])) {
$title = $_POST["request_title"];
$date = $_POST["request_date"];
$eDate = $_POST["reqEndDate"];
$reason = $_POST["reason"];
$requestor = $_POST["requestor"];
$status = $_POST["status"];
$dateSubmitted = $_POST["submitDate"];
$explanation = $_POST["explanation"];
$numhours = $_POST["hours"];
$id = $_POST['id'];
// mysql inserting a new row
$result = mysql_query("INSERT INTO requests(request_title, request_date, reqEndDate, reason, requestor, status, submitDate, explanation, hours, empid)
VALUES('$title', '$date', '$eDate', '$reason', '$requestor', '$status', '$dateSubmitted', '$explanation', '$numhours', '$id')");
?>
JAVA CLASS
// url to the PHP API to create new request
private static String url_create_request = "http://mywebsite.com/create_request.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_request);
// Edit Text
inputTitle = (EditText) findViewById(R.id.inputTitle);
inputSdate = (EditText) findViewById(R.id.inputSdate);
inputEdate = (EditText) findViewById(R.id.inputEdate);
inputHours = (EditText) findViewById(R.id.inputHours);
inputReason = (EditText) findViewById(R.id.inputReason);
inputExp = (EditText) findViewById(R.id.inputExp);
// Create button
Button btnCreateRequest = (Button) findViewById(R.id.btnCreateRequest);
// button click event
btnCreateRequest.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// creating new product in background thread
new CreateNewRequest().execute();
}
});
}
class CreateNewRequest extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(NewRequestActivity.this);
pDialog.setMessage("Creating Request..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Creating Request Required Fields
* */
protected String doInBackground(String... args) {
String title = inputTitle.getText().toString();
String date = inputSdate.getText().toString();
String eDate = inputEdate.getText().toString();
String hours = inputHours.getText().toString();
String reason = inputReason.getText().toString();
String explanation = inputExp.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("request_title", title));
params.add(new BasicNameValuePair("request_date", date));
params.add(new BasicNameValuePair("reqEndDate", eDate));
params.add(new BasicNameValuePair("hours", hours));
params.add(new BasicNameValuePair("reason", reason));
params.add(new BasicNameValuePair("explanation", explanation));
// getting JSON Object
// Note that create request url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_request,
"POST", params);
// check log cat fro response
Log.d("Create Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created request
Intent i = new Intent(getApplicationContext(), AllRequestsActivity.class);
startActivity(i);
// closing this screen
finish();
} else {
// failed to create request
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
}
}
}
Just counting your DB columns: there appears to be 12 of them. You're only inserting into 11, and after process of elimination, it looks like you're leaving out "active," which, unless it has a default value or can be null, would throw a "Required field(s) is missing" error that you're getting when trying to insert into the DB.