简体   繁体   中英

Php from android in json not posting to table, is there something wrong in my code?

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);
?>

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM