2015-10-26 49 views
-1

我從形式角以下職位:角PHP投遞到MYSQL,添加字符串變量

$postdata = file_get_contents("php://input"); 
$request = json_decode($postdata); 
@$id = $request->id; 
@$cid = $request->cid; 
@$description = $request->description; 
@$type = $request->type; 
@$owner = $request->owner; 
@$ssamount = $request->ssamount; 
if($owner == 'spouse' && $type == 'ira') 
{$exempt == 'yes'}; 
if(mysqli_connect_errno()) { Etc... 

我試圖做到的是將某些邏輯在PHP,而不是客戶端。如果來自Angular JSON發佈文件的兩個變量符合所示的條件,我希望MYSQL數據庫中的另一個字段設置爲yes或no。上面的豁免$。

我沒有得到任何錯誤,但它不會更改MYSQL中的字段。我認爲這個問題可能與解碼的JSON的結構有關,或者我可能在解碼之前將這個JSON對象添加到$ postdata中。

任何想法?謝謝

+2

這是失敗'{$ exempt =='是'};'出於兩個原因。 –

回答

0

特別是在你的代碼就應該更換:

if($owner == 'spouse' && $type == 'ira') 
{$exempt == 'yes'}; 

if($owner == 'spouse' && $type == 'ira') { 
    $exempt = 'yes'; 
} 

雙等號是比較運算符而單等號是賦值運算符。

+0

謝謝安德魯。有時候調試就像玩Waldo的Where's一樣。 – user2690440