gpt4 book ai didi

php - JSONException : Value
转载 作者:行者123 更新时间:2023-11-29 17:19:34 25 4
gpt4 key购买 nike

我正在使用 xampp 服务器和 MySQL 数据库制作一个简单的登录页面。我不断收到上述错误,不幸的是,找不到正确的答案。我正在使用真正的 Android 手机而不是模拟器。日志框似乎没有显示任何类型的错误,所以我不确定出了什么问题。提前致谢

LoginActivity.java

public class LoginActivity extends AppCompatActivity {

private static String LOGIN_URL = "http://192.168.43.231/Login/login.php";
public static final String KEY_USERNAME = "username";
public static final String KEY_PASSWORD = "password";

@Override
protected void onCreate(Bundle savedInstanceState) {
.....
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String usernameS = username.getText().toString().trim();
final String passwordS = password.getText().toString().trim();

if (usernameS.isEmpty() || passwordS.isEmpty()) {
Toast.makeText(LoginActivity.this, "Enter Valid Username & Password", Toast.LENGTH_SHORT).show();
} else {

StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
boolean responseStatus = jsonObject.getBoolean("success");
if (responseStatus) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
LoginActivity.this.startActivity(intent);
} else {
Toast.makeText(LoginActivity.this, "Invalid Username or Password", Toast.LENGTH_SHORT).show();

}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(LoginActivity.this,"Error" + e.toString(), Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(LoginActivity.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_USERNAME, usernameS);
params.put(KEY_PASSWORD, passwordS);

return params;
}
};
RequestQueue requestQueue =Volley.newRequestQueue(LoginActivity.this);
requestQueue.add(stringRequest);
}
}
});
}

}

PHP 代码

<?php
$con=mysqli_connect("localhost","root","","blast");

$username=$_POST['username']);
$password=$_POST['password']);

$sql=mysqli_prepare($con,"SELECT * from blast_user where username = '$username' and password = '$password'");
mysqli_stmt_bind_param($sql,"sss",$username,$password);
mysqli_stmt_execute($sql);
mysqli_stmt_store_result($sql);
mysqli_stmt_bind_result($sql,$username,$password);

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

echo json_encode($response);
>?

最佳答案

这样做 -

$username=$_POST['usernameS']);
$password=$_POST['passwordS']);

而不是-

$username=$_POST['username']);
$password=$_POST['password']);

关于php - JSONException : Value <br cannot be converted into JSONobject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51331314/

25 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com