2015-10-26 47 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