duandie0884 2014-11-19 16:45
浏览 31
已采纳

来自json的android中的Php没有发布到表中,我的代码中有什么问题吗?

I have an android app converting info into JSON and sending it to php/MySQL, get response back on the phone just fine but nothing is getting into the table, I'm not that experienced in php, did I screw up this code?

<?php
include('../htconfig/dbConfig.php'); 
$dbSuccess = false;
    $dbConnected = mysql_connect($db['hostname'],$db['username'],$db['password']);

    if ($dbConnected) {     
        $dbSelected = mysql_select_db($db['database'],$dbConnected);
        if ($dbSelected) {
            $dbSuccess = true;
        }   
    }
$data_back = json_decode(file_get_contents('php://input'));


$userName = $data_back->{"User"};
$password = $data_back->{"Pword"};
$PurchasedFrom = $data_back->{"Pfrom"};
$VIN = $data_back->{"VIN"};
$Color = $data_back->{"Color"};
$MakeIndex = $data_back->{"Make"};
$ModelIndex= $data_back->{"Model"};
$Year = $data_back->{"Year"};
$Bid = $data_back->{"Bid"};
$INV = $data_back->{"PurchasePrice"};
$BidContact = $data_back->{"Contact"};
$BidEmail= $data_back->{"Email"};


mysql_query("Insert Into tblinventory (VIN, MakeIndex, ModelIndex, Year, Color,Bid,INV, 
BidContact, BidEmail, PurchasedFrom)
VALUES ('$VIN','$MakeIndex', '$ModelIndex', '$Year', '$Color', '$Bid', 
'$INV', '$BidContact', '$BidEmail', '$PurchasedFrom')");

$responses = array();
 {
    $responses[] = array( $VIN . " " . $MakeIndex . " " . $ModelIndex." ". $Year." " );
}


header("Content-type: application/json");


echo json_encode($responses);
?>
  • 写回答

1条回答 默认 最新

  • doutanghuan9595 2014-11-19 17:19
    关注

    Needed to add error checking code and make sure there is an actual database connection. Also make sure your input and query have the same name..see PurchasedFrom and Pfrom. Thanks for the help guys and thanks for the links, they will help a lot. Happy Coding :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起