drvonr6573 2016-05-02 20:42
浏览 25

json异常与php文件中的会话

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)