【问题标题】:Angular PHP Post to MYSQL, Add String Variable [duplicate]Angular PHP Post到MYSQL,添加字符串变量[重复]
【发布时间】:2016-01-26 05:48:41
【问题描述】:

我在 Angular 中的表单中有以下帖子:

$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 数据库中的另一个字段设置为是或否。 $exempt 在上面。

我没有收到任何错误,但它不会更改 MYSQL 中的字段。我认为问题可能与解码后的 JSON 的结构有关,或者我可能必须在解码之前将此 JSON 对象添加到 $postdata。

有什么想法吗?谢谢

【问题讨论】:

  • 这失败了{$exempt == 'yes'}; 有两个原因。

标签: php mysql json angularjs


【解决方案1】:

特别是在你的代码中你应该替换:

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

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

双等号是比较运算符,单等号是赋值运算符。

【讨论】:

  • 谢谢安德鲁。有时调试就像玩Where's Waldo。
猜你喜欢
  • 1970-01-01
  • 2015-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-07
  • 1970-01-01
相关资源
最近更新 更多