Here is the php script I'm using for registration of new users
PHP
<?php
require "init.php";
$name = $_POST["user"];
$user_name = $_POST["user_name"];
$user_pass = $_POST["user_pass"];
$sql_query = "insert into user_info values('$name','$user_name','$user_pass');";
?>
Android Log
06-10 19:55:40.395 4694-4838/com.example.clint.mysqltesting W/System.err: java.io.FileNotFoundException: http://192.168.0.103/webapp/register.php
My Background Task BackgroundTask.java
package com.example.clint.mysqltesting;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
/**
* Created by CLINT on 6/11/2016.
*/
public class BackgroundTask extends AsyncTask<String, Void, String> {
Context ctx;
BackgroundTask(Context ctx){
this.ctx = ctx;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String reg_url = "http://192.168.0.103/webapp/register.php";
String login_url = "http://192.168.0.103/webapp/login.php";
String method = params[0];
if(method.equals("register")){
String name = params[1];
String user_name = params[2];
String user_pass = params[3];
try {
URL url = new URL(reg_url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream OS = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS, "UTF-8"));
String data = URLEncoder.encode("user", "UTF-8")+ "=" +URLEncoder.encode(name, "UTF-8")+ "&" +
URLEncoder.encode("user_name", "UTF-8")+ "=" +URLEncoder.encode(user_name, "UTF-8")+ "&"
+URLEncoder.encode("user_pass", "UTF-8")+ "=" +URLEncoder.encode(user_pass, "UTF-8");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
OS.close();
InputStream IS = httpURLConnection.getInputStream();
IS.close();
return "registration Success";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(ctx, result, Toast.LENGTH_LONG).show();
}
}
What is the reason that I am getting an Undefined Index? I have seen some questions related to this that are saying use the (isset) can resolve this trouble. I have tried doing this, but still not able to add the data to the database from the Android app.