PHP returns undefined index to Android studio [duplicate]












0
















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Sending POST data in Android

    15 answers




Im trying to connect Android Studio to a localhost MySQL server. I believe something is wrong with my php file, and I don't know how to fix it. I tried using isset, but that doesn't seem to work. Its supposed to be a simple registration script



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

$con = mysqli_connect($db_host,'root',$db_pass,$db_name);
if($con){
echo "connection successful";
}
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}

$isAdmin = $_POST["isAdmin"];//line 16
$username = $_POST["username"];
$password = $_POST["password"];
if ($isAdmin = null){
$isAdmin = 0;
}
if ($username = null){
$username = "fakename";
}
if ($password = null){
$password = "fakepassword";
}
$statement = mysqli_prepare($con, "INSERT INTO cresidentials (username,password,isAdmin) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($statement,'ssi',$username,$password,$isAdmin);
mysqli_stmt_execute($statement);
if(!$statement) { printf("Prepare failed: %sn", mysqli_error($con)); }
echo "success";
?>


The error says




undefined index: isAdmin, username, password at line 16-18




I tried replacing POST with isset, but that doesn't seem to work. It may be how its getting the info, so ill provide the registerrequest here;



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;
}
}


I tried to echo my variables, since everyone seems to do that, but i still get nothing. Isset just doesn't seem to do anything, and gives the same error. I might be using it wrong, however.



And just in case I'm not using jsonobjects properly, here is the register script;



public class CreateUser extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_user);
this.setTitle("Create User");
final EditText username1 = findViewById(R.id.Createusername);
final EditText password1 = findViewById(R.id.CreatePassword);
final Switch isAdmin = findViewById(R.id.isadmin);
final Button createuser = findViewById(R.id.createuserbtn);
if (getIntent().hasExtra("com.example.northlandcaps.crisis_response")){
isAdmin.setVisibility(View.GONE);
}
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);
}
});
}


Thanks for the help










share|improve this question















marked as duplicate by miken32, RiggsFolly mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 15:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • $isAdmin = $_POST["isAdmin"] ?? null;

    – miken32
    Nov 14 '18 at 15:23











  • Did you try a simple var_dump($_POST) and then look at what is returned to the browser/code

    – RiggsFolly
    Nov 14 '18 at 15:24











  • @miken32 am i supposed to put that in the script? or is that a question?

    – Alec Harvey
    Nov 14 '18 at 15:26











  • @RiggsFolly not yet

    – Alec Harvey
    Nov 14 '18 at 15:26











  • @AlecHarvey did you try debugging your php script ? trial and error can take forever, get yourself an IDE with xdebug and see for yourself what you are getting (or not) in $_POST.

    – YvesLeBorg
    Nov 14 '18 at 15:28
















0
















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Sending POST data in Android

    15 answers




Im trying to connect Android Studio to a localhost MySQL server. I believe something is wrong with my php file, and I don't know how to fix it. I tried using isset, but that doesn't seem to work. Its supposed to be a simple registration script



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

$con = mysqli_connect($db_host,'root',$db_pass,$db_name);
if($con){
echo "connection successful";
}
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}

$isAdmin = $_POST["isAdmin"];//line 16
$username = $_POST["username"];
$password = $_POST["password"];
if ($isAdmin = null){
$isAdmin = 0;
}
if ($username = null){
$username = "fakename";
}
if ($password = null){
$password = "fakepassword";
}
$statement = mysqli_prepare($con, "INSERT INTO cresidentials (username,password,isAdmin) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($statement,'ssi',$username,$password,$isAdmin);
mysqli_stmt_execute($statement);
if(!$statement) { printf("Prepare failed: %sn", mysqli_error($con)); }
echo "success";
?>


The error says




undefined index: isAdmin, username, password at line 16-18




I tried replacing POST with isset, but that doesn't seem to work. It may be how its getting the info, so ill provide the registerrequest here;



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;
}
}


I tried to echo my variables, since everyone seems to do that, but i still get nothing. Isset just doesn't seem to do anything, and gives the same error. I might be using it wrong, however.



And just in case I'm not using jsonobjects properly, here is the register script;



public class CreateUser extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_user);
this.setTitle("Create User");
final EditText username1 = findViewById(R.id.Createusername);
final EditText password1 = findViewById(R.id.CreatePassword);
final Switch isAdmin = findViewById(R.id.isadmin);
final Button createuser = findViewById(R.id.createuserbtn);
if (getIntent().hasExtra("com.example.northlandcaps.crisis_response")){
isAdmin.setVisibility(View.GONE);
}
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);
}
});
}


Thanks for the help










share|improve this question















marked as duplicate by miken32, RiggsFolly mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 15:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • $isAdmin = $_POST["isAdmin"] ?? null;

    – miken32
    Nov 14 '18 at 15:23











  • Did you try a simple var_dump($_POST) and then look at what is returned to the browser/code

    – RiggsFolly
    Nov 14 '18 at 15:24











  • @miken32 am i supposed to put that in the script? or is that a question?

    – Alec Harvey
    Nov 14 '18 at 15:26











  • @RiggsFolly not yet

    – Alec Harvey
    Nov 14 '18 at 15:26











  • @AlecHarvey did you try debugging your php script ? trial and error can take forever, get yourself an IDE with xdebug and see for yourself what you are getting (or not) in $_POST.

    – YvesLeBorg
    Nov 14 '18 at 15:28














0












0








0









This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Sending POST data in Android

    15 answers




Im trying to connect Android Studio to a localhost MySQL server. I believe something is wrong with my php file, and I don't know how to fix it. I tried using isset, but that doesn't seem to work. Its supposed to be a simple registration script



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

$con = mysqli_connect($db_host,'root',$db_pass,$db_name);
if($con){
echo "connection successful";
}
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}

$isAdmin = $_POST["isAdmin"];//line 16
$username = $_POST["username"];
$password = $_POST["password"];
if ($isAdmin = null){
$isAdmin = 0;
}
if ($username = null){
$username = "fakename";
}
if ($password = null){
$password = "fakepassword";
}
$statement = mysqli_prepare($con, "INSERT INTO cresidentials (username,password,isAdmin) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($statement,'ssi',$username,$password,$isAdmin);
mysqli_stmt_execute($statement);
if(!$statement) { printf("Prepare failed: %sn", mysqli_error($con)); }
echo "success";
?>


The error says




undefined index: isAdmin, username, password at line 16-18




I tried replacing POST with isset, but that doesn't seem to work. It may be how its getting the info, so ill provide the registerrequest here;



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;
}
}


I tried to echo my variables, since everyone seems to do that, but i still get nothing. Isset just doesn't seem to do anything, and gives the same error. I might be using it wrong, however.



And just in case I'm not using jsonobjects properly, here is the register script;



public class CreateUser extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_user);
this.setTitle("Create User");
final EditText username1 = findViewById(R.id.Createusername);
final EditText password1 = findViewById(R.id.CreatePassword);
final Switch isAdmin = findViewById(R.id.isadmin);
final Button createuser = findViewById(R.id.createuserbtn);
if (getIntent().hasExtra("com.example.northlandcaps.crisis_response")){
isAdmin.setVisibility(View.GONE);
}
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);
}
});
}


Thanks for the help










share|improve this question

















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Sending POST data in Android

    15 answers




Im trying to connect Android Studio to a localhost MySQL server. I believe something is wrong with my php file, and I don't know how to fix it. I tried using isset, but that doesn't seem to work. Its supposed to be a simple registration script



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

$con = mysqli_connect($db_host,'root',$db_pass,$db_name);
if($con){
echo "connection successful";
}
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}

$isAdmin = $_POST["isAdmin"];//line 16
$username = $_POST["username"];
$password = $_POST["password"];
if ($isAdmin = null){
$isAdmin = 0;
}
if ($username = null){
$username = "fakename";
}
if ($password = null){
$password = "fakepassword";
}
$statement = mysqli_prepare($con, "INSERT INTO cresidentials (username,password,isAdmin) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($statement,'ssi',$username,$password,$isAdmin);
mysqli_stmt_execute($statement);
if(!$statement) { printf("Prepare failed: %sn", mysqli_error($con)); }
echo "success";
?>


The error says




undefined index: isAdmin, username, password at line 16-18




I tried replacing POST with isset, but that doesn't seem to work. It may be how its getting the info, so ill provide the registerrequest here;



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;
}
}


I tried to echo my variables, since everyone seems to do that, but i still get nothing. Isset just doesn't seem to do anything, and gives the same error. I might be using it wrong, however.



And just in case I'm not using jsonobjects properly, here is the register script;



public class CreateUser extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_user);
this.setTitle("Create User");
final EditText username1 = findViewById(R.id.Createusername);
final EditText password1 = findViewById(R.id.CreatePassword);
final Switch isAdmin = findViewById(R.id.isadmin);
final Button createuser = findViewById(R.id.createuserbtn);
if (getIntent().hasExtra("com.example.northlandcaps.crisis_response")){
isAdmin.setVisibility(View.GONE);
}
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);
}
});
}


Thanks for the help





This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Sending POST data in Android

    15 answers








php android mysql android-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 14:38









RiggsFolly

70.7k1864111




70.7k1864111










asked Nov 14 '18 at 15:14









Alec HarveyAlec Harvey

568




568




marked as duplicate by miken32, RiggsFolly mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 15:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by miken32, RiggsFolly mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 15:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • $isAdmin = $_POST["isAdmin"] ?? null;

    – miken32
    Nov 14 '18 at 15:23











  • Did you try a simple var_dump($_POST) and then look at what is returned to the browser/code

    – RiggsFolly
    Nov 14 '18 at 15:24











  • @miken32 am i supposed to put that in the script? or is that a question?

    – Alec Harvey
    Nov 14 '18 at 15:26











  • @RiggsFolly not yet

    – Alec Harvey
    Nov 14 '18 at 15:26











  • @AlecHarvey did you try debugging your php script ? trial and error can take forever, get yourself an IDE with xdebug and see for yourself what you are getting (or not) in $_POST.

    – YvesLeBorg
    Nov 14 '18 at 15:28



















  • $isAdmin = $_POST["isAdmin"] ?? null;

    – miken32
    Nov 14 '18 at 15:23











  • Did you try a simple var_dump($_POST) and then look at what is returned to the browser/code

    – RiggsFolly
    Nov 14 '18 at 15:24











  • @miken32 am i supposed to put that in the script? or is that a question?

    – Alec Harvey
    Nov 14 '18 at 15:26











  • @RiggsFolly not yet

    – Alec Harvey
    Nov 14 '18 at 15:26











  • @AlecHarvey did you try debugging your php script ? trial and error can take forever, get yourself an IDE with xdebug and see for yourself what you are getting (or not) in $_POST.

    – YvesLeBorg
    Nov 14 '18 at 15:28

















$isAdmin = $_POST["isAdmin"] ?? null;

– miken32
Nov 14 '18 at 15:23





$isAdmin = $_POST["isAdmin"] ?? null;

– miken32
Nov 14 '18 at 15:23













Did you try a simple var_dump($_POST) and then look at what is returned to the browser/code

– RiggsFolly
Nov 14 '18 at 15:24





Did you try a simple var_dump($_POST) and then look at what is returned to the browser/code

– RiggsFolly
Nov 14 '18 at 15:24













@miken32 am i supposed to put that in the script? or is that a question?

– Alec Harvey
Nov 14 '18 at 15:26





@miken32 am i supposed to put that in the script? or is that a question?

– Alec Harvey
Nov 14 '18 at 15:26













@RiggsFolly not yet

– Alec Harvey
Nov 14 '18 at 15:26





@RiggsFolly not yet

– Alec Harvey
Nov 14 '18 at 15:26













@AlecHarvey did you try debugging your php script ? trial and error can take forever, get yourself an IDE with xdebug and see for yourself what you are getting (or not) in $_POST.

– YvesLeBorg
Nov 14 '18 at 15:28





@AlecHarvey did you try debugging your php script ? trial and error can take forever, get yourself an IDE with xdebug and see for yourself what you are getting (or not) in $_POST.

– YvesLeBorg
Nov 14 '18 at 15:28












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Bressuire

Vorschmack

Quarantine