I am trying to connect my android app with database on my local server. It is actually connecting but when its trying to perform insertion into database , I am getting errors:
Notice: Undefined index: user_login in C:\wamp\www\webapp\register.php on line 4
Notice: Undefined index: user_password in C:\wamp\www\webapp\register.php on line 5
Notice: Undefined index: user_phonenumber in C:\wamp\www\webapp\register.php on line 6
Notice: Undefined index: user_email in C:\wamp\www\webapp\register.php on line 7
On my register.php i have
require "init.php";
$user_login = $_POST["user_login"];
$user_password = $_POST["user_password"];
$user_phonenumber = $_POST["user_phonenumber"];
$user_email = $_POST["user_email"];
$sql_query = "insert into user_db values('$user_login','$user_password','$user_phonenumber','$user_email');";
Android code :
URL url = new URL(reg_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream OS = httpURLConnection.getOutputStream();
Log.d("in background", " connected");
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS,"UTF-8"));
String data = URLEncoder.encode("user_login","UTF-8") + "="+URLEncoder.encode(Loginstr,"UTF-8")+"&"+
URLEncoder.encode("user_password","UTF-8") + "="+URLEncoder.encode(Passwordstr,"UTF-8")+"&"+
URLEncoder.encode("user_phonenumber","UTF-8") + "="+URLEncoder.encode(Numberstr,"UTF-8")+"&"+
URLEncoder.encode("user_email","UTF-8") + "="+URLEncoder.encode( Emailstr,"UTF-8");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
OS.close();
InputStream IS = httpURLConnection.getInputStream();
IS.close();
I would also ask how to make one thing. In my database I have created to be filled by new user and one field created to hold unique id for user. My question is: After creation of new user , will this id field be filed with new uniqe id corelated with user? (AUTO_INCREMENT
option is marked). If not , what should i do to make such a thing.
I am really new with SQL and PHP so i hope I have explained everything correct. Thanks in advance