为什么数据库无法发送数据? [英] Why is the database failed to send data?

查看:101
本文介绍了为什么数据库无法发送数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试使用Json发送数据,但失败了。当我使用jsonviewer时,我发现它只读取了我的结构的一部分(我有'pid','name','price','description','uses','sideeffects','precauctions','interaction', '过量,它只能读'名字','价格','描述'):



下面是php代码:

I have tried to use Json to send data but it failed. When I use the jsonviewer, I find it only read part of my structure(I have 'pid','name', 'price' , 'description', 'uses', 'sideeffects', 'precauctions', 'interactions', 'overdose, it can only read 'name', 'price' , 'description'):

Below is the php code:

<?php

/*
 * Following code will get single product details
 * A product is identified by product id (pid)
 */

// array for JSON response
$response = array();


// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// check for post data
if (isset($_GET["pid"])) {
    $pid = $_GET['pid'];

    // get a product from products table
    $result = mysql_query("SELECT *FROM products WHERE pid = $pid");

    if (!empty($result)) {
        // check for empty result
        if (mysql_num_rows($result) > 0) {

            $result = mysql_fetch_array($result);

            $product = array();
            $product["pid"] = $result["pid"];
            $product["name"] = $result["name"];
            $product["price"] = $result["price"];
            $product["description"] = $result["description"];
            $product["uses"] = $result["uses"];
            $product["sideeffects"] = $result["sideeffects"];
            $product["precauctions"] = $result["precauctions"];
            $product["interactions"] = $result["interactions"];
            $product["overdose"] = $result["overdose"];
            $product["created_at"] = $result["created_at"];
            $product["updated_at"] = $result["updated_at"];
            // success
            $response["success"] = 1;

            // user node
            $response["product"] = array();

            array_push($response["product"], $product);

            // echoing JSON response
            echo json_encode($response);
        } else {
            // no product found
            $response["success"] = 0;
            $response["message"] = "No product found";

            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // no product found
        $response["success"] = 0;
        $response["message"] = "No product found";

        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}
?>

推荐答案

response = array();


//包括db connect class
require_once __DIR__。 '/db_connect.php';

//连接到db
response = array(); // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db


db = new DB_CONNECT();

//检查发布数据
if(isset(
db = new DB_CONNECT(); // check for post data if (isset(


_GET [pid])){
_GET["pid"])) {


这篇关于为什么数据库无法发送数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆