在互联网上寻找一个想法几个小时没有成功,我在这里写我的问题。 我正在使用会话来获取其他php文件中的变量。 当我在Android studio中创建json时,出现错误。我尝试了一些测试来查看问题是否是会话,当我将会话代码放入注释时,我的代码运行良好。 我想知道我的android文件是否需要允许会话或其他任何东西因为我的所有php文件都能正常工作。
我的代码如下:
php文件发布了params(Login.php)
if (isset($_POST['email']) && isset($_POST['password'])) {
$email = $_POST['email'];
$_SESSION['email'] = $email;
$password = $_POST['password'];}
php文件,其中包含我需要的所有功能(它是使用会话来获取电子邮件的功能)(DB_Functions.php)
<?php session_start();
public function getIdByEmail() {
$stmt = $this->conn->prepare("SELECT id FROM users WHERE email = ?");
$stmt->bind_param("s",$_SESSION['email']);
$result = $stmt->execute();
if ($result) {
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
return $user;
} else {
return NULL;
}
session_destroy();
}
?>
在其他php文件中调用此函数来存储id
问题来自:(android文件)
String uid = jObj.getString("uid");
JSONObject candidate = jObj.getJSONObject("candidate");
int id_users_fk = candidate.getInt("id_users_fk");
String name = candidate.getString("name");
String firstname = candidate.getString("firstname");
String training = candidate.getString("training");
String areaActivity = candidate.getString("area_activity");
String type = candidate.getString("type");
String language1 = candidate.getString("language1");
String levelLanguage1 = candidate.getString("level_language1");
String language2 = candidate.getString("language2");
String levelLanguage2 = candidate.getString("level_language2");
String language3 = candidate.getString("language3");
String levelLanguage3 = candidate.getString("level_language3");
String skill = candidate.getString("skill");
String geolocation = candidate.getString("geolocation");
String created_at = candidate.getString("created_at");
db.addNewCandidate(id_users_fk, name, firstname, training, areaActivity, type,
language1, levelLanguage1, language2, levelLanguage2,
language3, levelLanguage3, skill, geolocation,
uid, created_at);
错误:
System.err:org.json.JSONException:类型为org.json.JSONObject $ 1的id_users_fk的值null无法转换为int