gpt4 book ai didi

php - 嵌套查询未运行,始终返回 null。

转载 作者:行者123 更新时间:2023-11-29 05:27:04 24 4
gpt4 key购买 nike

我正在开发一个移动应用程序,当用户登录 php/mysql 网络服务器时,用户详细信息通过 json 存储在本地 sqlite 数据库中。

这很好用。接下来,我尝试从 mysql 数据库中的另一个表更新第二个 sqlite 表。

第二次查询返回的json始终为null。 (查询单独运行没问题)

我可以像这样运行两个查询吗??有什么想法吗?

谢谢。

<?php

include 'DB_Connect.php';


// get tag
if (isset($_POST['email']) && $_POST['email'] != '') {
$tag = 'login';

//json response array
$response = array();

// check for tag type
if ($tag == 'login') {

$email = $_POST['email'];
$password = $_POST['password'];

//check user exists
$qry = "SELECT uid, name, email, registration_date, updated_at FROM users WHERE email = ? AND password = ? ";
$stmt = $mysqli->prepare($qry);
$stmt->bind_param('ss', $email, $password);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($uid, $name, $email, $registration_date, $updated_at); // get variables from result.
$stmt->fetch();
if ($stmt->num_rows == 1){

// if user exists, set json values
$response["success"] = 1;
$response["uid"] = $uid;
$response["user"]["name"] = $name;
$response["user"]["email"] = $email;
$response["user"]["registration_date"] = $registration_date;
$response["user"]["updated_at"] = $updated_at;
echo json_encode($response);
$stmt->close();

if ($response["success"] = 1 ){
$qry = "SELECT device_name, device_registration_date FROM devices WHERE parent_id =?";
$stmt = $mysqli->prepare($qry);
$stmt->bind_param('s',$uid);
$stmt->store_result();
$stmt->bind_result($device_name, $device_registration_date); // get variables from result.
$stmt->fetch();
$response2["device"]["device_name"] = $device_name;
$response2["device"]["device_registration_date"] = $device_registration_date;
echo json_encode($response2);
}

else if ($tag = 'register' ... blah blah blah .....

最佳答案

我希望这能解决问题:

if ($response["success"] = 1 ){

应该是:

if ($response["success"] == 1 ){

(if 中的两个相等)

关于php - 嵌套查询未运行,始终返回 null。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18933803/

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