Android studio isnt posting data in the PHP script “Unidentified index”











up vote
0
down vote

favorite












I have a simple register request script. My Android Studio is supposed to send 3 string over to the URL(php script), but the PHP doesn't receive any data, or is handling it poorly.



This is the RegisterRequest script:(its supposed to recieve values from within android studio and then push the info into the PHP script using POST method, located on localhost/ip address)



public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL = "http://192.168.*.*:80/phptesting/Register.php";
private Map<String, String> params;
public RegisterRequest(String username, String password,String isAdmin, Response.Listener<String> listener){
super(Method.POST, REGISTER_REQUEST_URL,listener,null);
params = new HashMap<>();
params.put("username",username);
params.put("password",password);
params.put("isAdmin",isAdmin+"");
}

public Map<String, String> getparams() {
return params;
}
}


Here is the CreateUser script. Its supposed to grab strings from the XML and then call the RegisterRequest class and hand over the strings;



createuser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final String username = username1.getText().toString();
final String password = password1.getText().toString();
final String isadmin = isAdmin.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response Value: ", response);
if (response.equals("success")){
Intent intent = new Intent(CreateUser.this, MainActivity.class);
CreateUser.this.startActivity(intent);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(CreateUser.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry",null)
.create()
.show();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(username,password,isadmin,responseListener);
RequestQueue queue = Volley.newRequestQueue(CreateUser.this);
queue.add(registerRequest);
}
});


And finally, here is my PHP script, which should receive Strings and put them into the db;



<?php
$db_host = 'localhost:3306';
$db_user = 'root';
$db_pass = '';
$db_name = 'test';

$con = mysqli_connect($db_host,'user',$db_pass,$db_name);
if($con){
echo "connection successful";
}else{
echo "connection failed";
}

$age = $_POST["isAdmin"];//line 14
$username = $_POST["username"];//line 15
$password = $_POST["password"];//line 16
$statement = mysqli_prepare($con, "INSERT INTO cresidentials (username,password,isAdmin) VALUES (?, ?, ?)");
if(!$statement) { printf("Prepare failed: %sn", mysqli_error($con)); }
if(!$statement) { return json_encode(['status'=>'failed','message'=>mysqli_error($con)]); }
mysqli_stmt_bind_param($statement, "ssi",$username,$password,$isAdmin);
mysqli_stmt_execute($statement);
if(mysqli_error($con)) { return json_encode(['status'=>'failed','message'=>mysqli_error($con)]); }//line 22

$response = array();
$response["success"] = true;

echo json_encode($response);
?>


I hope my explanation of the script functions help you guys on debugging the problem. Also, android studio outputs this;




Notice: Undefined index: isAdmin in Register.php on line 14
Notice: Undefined index: username in Register.php on line 15
Notice: Undefined index: password in Register.php on line 16




(Is it Android studio not sending the data over? or PHP not assigning what is receiving? does PHP need a method just to put data in?)



Thank you for your help










share|improve this question
























  • I believe $_POST needs to be used when you are receiving data using HTTP POST method. Where as you are using PUT method from android. That could be an issue.
    – Nik
    Nov 8 at 5:02










  • @Nik So how does PHP need to be structured to receive this "raw" PUT from Android?
    – Alec Harvey
    Nov 8 at 5:03










  • Check this PHP Manual page: php.net/manual/en/features.file-upload.put-method.php. Just curious why are you using PUT method and not POST?
    – Nik
    Nov 8 at 5:15












  • @Nik i am actually using PUT because my script is a culmination of StackOverflow, Indian YT videos, and unhelpful manual/guide pages for syntax. But if you suggest to replace PUT with POST, then ill try it
    – Alec Harvey
    Nov 8 at 5:16






  • 1




    @Nik i cannot seem to replace put in android with POST, so it seems like that is an Android thing
    – Alec Harvey
    Nov 8 at 5:18















up vote
0
down vote

favorite












I have a simple register request script. My Android Studio is supposed to send 3 string over to the URL(php script), but the PHP doesn't receive any data, or is handling it poorly.



This is the RegisterRequest script:(its supposed to recieve values from within android studio and then push the info into the PHP script using POST method, located on localhost/ip address)



public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL = "http://192.168.*.*:80/phptesting/Register.php";
private Map<String, String> params;
public RegisterRequest(String username, String password,String isAdmin, Response.Listener<String> listener){
super(Method.POST, REGISTER_REQUEST_URL,listener,null);
params = new HashMap<>();
params.put("username",username);
params.put("password",password);
params.put("isAdmin",isAdmin+"");
}

public Map<String, String> getparams() {
return params;
}
}


Here is the CreateUser script. Its supposed to grab strings from the XML and then call the RegisterRequest class and hand over the strings;



createuser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final String username = username1.getText().toString();
final String password = password1.getText().toString();
final String isadmin = isAdmin.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response Value: ", response);
if (response.equals("success")){
Intent intent = new Intent(CreateUser.this, MainActivity.class);
CreateUser.this.startActivity(intent);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(CreateUser.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry",null)
.create()
.show();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(username,password,isadmin,responseListener);
RequestQueue queue = Volley.newRequestQueue(CreateUser.this);
queue.add(registerRequest);
}
});


And finally, here is my PHP script, which should receive Strings and put them into the db;



<?php
$db_host = 'localhost:3306';
$db_user = 'root';
$db_pass = '';
$db_name = 'test';

$con = mysqli_connect($db_host,'user',$db_pass,$db_name);
if($con){
echo "connection successful";
}else{
echo "connection failed";
}

$age = $_POST["isAdmin"];//line 14
$username = $_POST["username"];//line 15
$password = $_POST["password"];//line 16
$statement = mysqli_prepare($con, "INSERT INTO cresidentials (username,password,isAdmin) VALUES (?, ?, ?)");
if(!$statement) { printf("Prepare failed: %sn", mysqli_error($con)); }
if(!$statement) { return json_encode(['status'=>'failed','message'=>mysqli_error($con)]); }
mysqli_stmt_bind_param($statement, "ssi",$username,$password,$isAdmin);
mysqli_stmt_execute($statement);
if(mysqli_error($con)) { return json_encode(['status'=>'failed','message'=>mysqli_error($con)]); }//line 22

$response = array();
$response["success"] = true;

echo json_encode($response);
?>


I hope my explanation of the script functions help you guys on debugging the problem. Also, android studio outputs this;




Notice: Undefined index: isAdmin in Register.php on line 14
Notice: Undefined index: username in Register.php on line 15
Notice: Undefined index: password in Register.php on line 16




(Is it Android studio not sending the data over? or PHP not assigning what is receiving? does PHP need a method just to put data in?)



Thank you for your help










share|improve this question
























  • I believe $_POST needs to be used when you are receiving data using HTTP POST method. Where as you are using PUT method from android. That could be an issue.
    – Nik
    Nov 8 at 5:02










  • @Nik So how does PHP need to be structured to receive this "raw" PUT from Android?
    – Alec Harvey
    Nov 8 at 5:03










  • Check this PHP Manual page: php.net/manual/en/features.file-upload.put-method.php. Just curious why are you using PUT method and not POST?
    – Nik
    Nov 8 at 5:15












  • @Nik i am actually using PUT because my script is a culmination of StackOverflow, Indian YT videos, and unhelpful manual/guide pages for syntax. But if you suggest to replace PUT with POST, then ill try it
    – Alec Harvey
    Nov 8 at 5:16






  • 1




    @Nik i cannot seem to replace put in android with POST, so it seems like that is an Android thing
    – Alec Harvey
    Nov 8 at 5:18













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a simple register request script. My Android Studio is supposed to send 3 string over to the URL(php script), but the PHP doesn't receive any data, or is handling it poorly.



This is the RegisterRequest script:(its supposed to recieve values from within android studio and then push the info into the PHP script using POST method, located on localhost/ip address)



public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL = "http://192.168.*.*:80/phptesting/Register.php";
private Map<String, String> params;
public RegisterRequest(String username, String password,String isAdmin, Response.Listener<String> listener){
super(Method.POST, REGISTER_REQUEST_URL,listener,null);
params = new HashMap<>();
params.put("username",username);
params.put("password",password);
params.put("isAdmin",isAdmin+"");
}

public Map<String, String> getparams() {
return params;
}
}


Here is the CreateUser script. Its supposed to grab strings from the XML and then call the RegisterRequest class and hand over the strings;



createuser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final String username = username1.getText().toString();
final String password = password1.getText().toString();
final String isadmin = isAdmin.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response Value: ", response);
if (response.equals("success")){
Intent intent = new Intent(CreateUser.this, MainActivity.class);
CreateUser.this.startActivity(intent);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(CreateUser.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry",null)
.create()
.show();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(username,password,isadmin,responseListener);
RequestQueue queue = Volley.newRequestQueue(CreateUser.this);
queue.add(registerRequest);
}
});


And finally, here is my PHP script, which should receive Strings and put them into the db;



<?php
$db_host = 'localhost:3306';
$db_user = 'root';
$db_pass = '';
$db_name = 'test';

$con = mysqli_connect($db_host,'user',$db_pass,$db_name);
if($con){
echo "connection successful";
}else{
echo "connection failed";
}

$age = $_POST["isAdmin"];//line 14
$username = $_POST["username"];//line 15
$password = $_POST["password"];//line 16
$statement = mysqli_prepare($con, "INSERT INTO cresidentials (username,password,isAdmin) VALUES (?, ?, ?)");
if(!$statement) { printf("Prepare failed: %sn", mysqli_error($con)); }
if(!$statement) { return json_encode(['status'=>'failed','message'=>mysqli_error($con)]); }
mysqli_stmt_bind_param($statement, "ssi",$username,$password,$isAdmin);
mysqli_stmt_execute($statement);
if(mysqli_error($con)) { return json_encode(['status'=>'failed','message'=>mysqli_error($con)]); }//line 22

$response = array();
$response["success"] = true;

echo json_encode($response);
?>


I hope my explanation of the script functions help you guys on debugging the problem. Also, android studio outputs this;




Notice: Undefined index: isAdmin in Register.php on line 14
Notice: Undefined index: username in Register.php on line 15
Notice: Undefined index: password in Register.php on line 16




(Is it Android studio not sending the data over? or PHP not assigning what is receiving? does PHP need a method just to put data in?)



Thank you for your help










share|improve this question















I have a simple register request script. My Android Studio is supposed to send 3 string over to the URL(php script), but the PHP doesn't receive any data, or is handling it poorly.



This is the RegisterRequest script:(its supposed to recieve values from within android studio and then push the info into the PHP script using POST method, located on localhost/ip address)



public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL = "http://192.168.*.*:80/phptesting/Register.php";
private Map<String, String> params;
public RegisterRequest(String username, String password,String isAdmin, Response.Listener<String> listener){
super(Method.POST, REGISTER_REQUEST_URL,listener,null);
params = new HashMap<>();
params.put("username",username);
params.put("password",password);
params.put("isAdmin",isAdmin+"");
}

public Map<String, String> getparams() {
return params;
}
}


Here is the CreateUser script. Its supposed to grab strings from the XML and then call the RegisterRequest class and hand over the strings;



createuser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final String username = username1.getText().toString();
final String password = password1.getText().toString();
final String isadmin = isAdmin.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response Value: ", response);
if (response.equals("success")){
Intent intent = new Intent(CreateUser.this, MainActivity.class);
CreateUser.this.startActivity(intent);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(CreateUser.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry",null)
.create()
.show();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(username,password,isadmin,responseListener);
RequestQueue queue = Volley.newRequestQueue(CreateUser.this);
queue.add(registerRequest);
}
});


And finally, here is my PHP script, which should receive Strings and put them into the db;



<?php
$db_host = 'localhost:3306';
$db_user = 'root';
$db_pass = '';
$db_name = 'test';

$con = mysqli_connect($db_host,'user',$db_pass,$db_name);
if($con){
echo "connection successful";
}else{
echo "connection failed";
}

$age = $_POST["isAdmin"];//line 14
$username = $_POST["username"];//line 15
$password = $_POST["password"];//line 16
$statement = mysqli_prepare($con, "INSERT INTO cresidentials (username,password,isAdmin) VALUES (?, ?, ?)");
if(!$statement) { printf("Prepare failed: %sn", mysqli_error($con)); }
if(!$statement) { return json_encode(['status'=>'failed','message'=>mysqli_error($con)]); }
mysqli_stmt_bind_param($statement, "ssi",$username,$password,$isAdmin);
mysqli_stmt_execute($statement);
if(mysqli_error($con)) { return json_encode(['status'=>'failed','message'=>mysqli_error($con)]); }//line 22

$response = array();
$response["success"] = true;

echo json_encode($response);
?>


I hope my explanation of the script functions help you guys on debugging the problem. Also, android studio outputs this;




Notice: Undefined index: isAdmin in Register.php on line 14
Notice: Undefined index: username in Register.php on line 15
Notice: Undefined index: password in Register.php on line 16




(Is it Android studio not sending the data over? or PHP not assigning what is receiving? does PHP need a method just to put data in?)



Thank you for your help







java php android android-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 5:45









Nik

1169




1169










asked Nov 8 at 4:57









Alec Harvey

388




388












  • I believe $_POST needs to be used when you are receiving data using HTTP POST method. Where as you are using PUT method from android. That could be an issue.
    – Nik
    Nov 8 at 5:02










  • @Nik So how does PHP need to be structured to receive this "raw" PUT from Android?
    – Alec Harvey
    Nov 8 at 5:03










  • Check this PHP Manual page: php.net/manual/en/features.file-upload.put-method.php. Just curious why are you using PUT method and not POST?
    – Nik
    Nov 8 at 5:15












  • @Nik i am actually using PUT because my script is a culmination of StackOverflow, Indian YT videos, and unhelpful manual/guide pages for syntax. But if you suggest to replace PUT with POST, then ill try it
    – Alec Harvey
    Nov 8 at 5:16






  • 1




    @Nik i cannot seem to replace put in android with POST, so it seems like that is an Android thing
    – Alec Harvey
    Nov 8 at 5:18


















  • I believe $_POST needs to be used when you are receiving data using HTTP POST method. Where as you are using PUT method from android. That could be an issue.
    – Nik
    Nov 8 at 5:02










  • @Nik So how does PHP need to be structured to receive this "raw" PUT from Android?
    – Alec Harvey
    Nov 8 at 5:03










  • Check this PHP Manual page: php.net/manual/en/features.file-upload.put-method.php. Just curious why are you using PUT method and not POST?
    – Nik
    Nov 8 at 5:15












  • @Nik i am actually using PUT because my script is a culmination of StackOverflow, Indian YT videos, and unhelpful manual/guide pages for syntax. But if you suggest to replace PUT with POST, then ill try it
    – Alec Harvey
    Nov 8 at 5:16






  • 1




    @Nik i cannot seem to replace put in android with POST, so it seems like that is an Android thing
    – Alec Harvey
    Nov 8 at 5:18
















I believe $_POST needs to be used when you are receiving data using HTTP POST method. Where as you are using PUT method from android. That could be an issue.
– Nik
Nov 8 at 5:02




I believe $_POST needs to be used when you are receiving data using HTTP POST method. Where as you are using PUT method from android. That could be an issue.
– Nik
Nov 8 at 5:02












@Nik So how does PHP need to be structured to receive this "raw" PUT from Android?
– Alec Harvey
Nov 8 at 5:03




@Nik So how does PHP need to be structured to receive this "raw" PUT from Android?
– Alec Harvey
Nov 8 at 5:03












Check this PHP Manual page: php.net/manual/en/features.file-upload.put-method.php. Just curious why are you using PUT method and not POST?
– Nik
Nov 8 at 5:15






Check this PHP Manual page: php.net/manual/en/features.file-upload.put-method.php. Just curious why are you using PUT method and not POST?
– Nik
Nov 8 at 5:15














@Nik i am actually using PUT because my script is a culmination of StackOverflow, Indian YT videos, and unhelpful manual/guide pages for syntax. But if you suggest to replace PUT with POST, then ill try it
– Alec Harvey
Nov 8 at 5:16




@Nik i am actually using PUT because my script is a culmination of StackOverflow, Indian YT videos, and unhelpful manual/guide pages for syntax. But if you suggest to replace PUT with POST, then ill try it
– Alec Harvey
Nov 8 at 5:16




1




1




@Nik i cannot seem to replace put in android with POST, so it seems like that is an Android thing
– Alec Harvey
Nov 8 at 5:18




@Nik i cannot seem to replace put in android with POST, so it seems like that is an Android thing
– Alec Harvey
Nov 8 at 5:18

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201786%2fandroid-studio-isnt-posting-data-in-the-php-script-unidentified-index%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201786%2fandroid-studio-isnt-posting-data-in-the-php-script-unidentified-index%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings