After looking for an idea on the internet for a few hours without success, I'm writing my question here. I'm using a session to get a variable in an other php file. When I create the json in Android studio, I get an error. I tried some tests to see if the problem was the session and when I put my session code in comments, my code works well. I'm wondering if my android file needs to allow a session or anything else because all of my php files work fine.
My code is bellow :
-
php file which posts the params (Login.php)
if (isset($_POST['email']) && isset($_POST['password'])) { $email = $_POST['email']; $_SESSION['email'] = $email; $password = $_POST['password'];}
-
php file which contains all the functions I need (it's the function which uses a session to get the email) (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(); } ?>
this function is called in an other php file to store the id
-
the problem comes from here : (android file)
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);
Error :
System.err: org.json.JSONException: Value null at id_users_fk of type org.json.JSONObject$1 cannot be converted to int