我真的需要你的帮助,有点紧张所以它可能会忽略迷你错误而只是遗漏了一些东西。我一直在我的桌面上为我的应用程序工作,但现在需要明天演示它,所以转移到笔记本电脑。将IP地址更改为笔记本电脑,通过php文件传输并导入mySQL。它是在本地到达php文件,但它说没有给出参数。代码没有改变。我还需要检查什么?作为一个新手我确实有一些复杂的设置在桌面上的一些时间agao ...但现在我确信我做了适当的转移步骤,但没有,现在不知道我的下一步。
PHP配置
<?php
/**
* Database connection variables 14/07/2016 12:52
* define: Defines constant (cannot change)
*/
define("DB_HOST", "localhost"); //db server
define("DB_USER", "boo"); //db user
define("DB_PASSWORD", "root"); //db password
define("DB_DATABASE", "brumbooc_famvsfam"); //db name
?>
** PHP Connect **
<?php
/**
* Handles opening and closing of the database connection
*/
class DB_Connect {
private $conn; //Dollar sign is a variable
// Connecting to database
public function connect() { //Method
require_once 'include/Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// return database handler
// Check connection
return $this->conn;
}
}
?>
PHP LOGIN ---它返回错误$ response [&#34; error_msg&#34;] =&#34;缺少必需参数的电子邮件或密码!&#34 ;;所以我知道java代码正在连接
<?php
require_once 'include/DB_Functions_Login.php';
$db = new DB_Functions_Login();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['email']) && isset($_POST['password'])) {
// receiving the post params
$email = $_POST['email'];
$password = $_POST['password'];
// get the user by email and password
$user = $db->getUserByEmailAndPassword($email, $password);
if ($user != false) {
// use is found
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["id"] = $user ["id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user is not found with the credentials
$response["error"] = TRUE;
$response["error_msg"] = "Login credentials are wrong. Please try again!";
echo json_encode($response);
}
} else {
// required post params is missing
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters email or password is missing!";
echo json_encode($response);
}
?>
排球请求
private void checkLogin(final String email, final String password) {
//Tag used to cancel the request
String tag_string_req = "req_login";
pDialog.setMessage("Loggin in ...");
showDialog();
StringRequest strReq = new StringRequest(Request.Method.POST,
PHPConfigLap.URL_LOGIN, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(methodName, "Login Activity Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
// user successfully logged in
// Create login session
session.setLogin(true);
// Now store the user in SQLite
String strLogInUID = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
// String id = user.getString("id");
mFamilyAccount.setID(user.getInt("id"));
String name = user.getString("name");
String email = user.getString("account_email");
String created_at = user
.getString("created_at");
int FamID = mFamilyAccount.getId();
inDB.addUser(name, email, strLogInUID, created_at, FamID);
Intent intent = new Intent(LoginActivity.this, BaseActivity.class);
startActivity(intent);
finish();
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(methodName, "Login Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<String, String>();
params.put("account_email", email);
params.put("password", password);
return params;
}
};
// TODO: 09/08/2016 replace with volley standard
NetworkManager.getInstance().addToRequestQueue(strReq, tag_string_req); //Old
}