2017-11-02 3 views
1

AngularJSからPHPにデータを送信しようとしています。AngularJSからPHPへのIF-ステートメントのためのデータの、PHPでの適切な構文の送信?

controller.jsからAngularJSのデータを送信しています。 PHPでデータを受信して​​います。データは他の変数にも適しています。

しかし、どの部分が問題なのかわかりません。

私の目標はPHP$step_numberと認識し、PHPのIF文を実行することですが、間違ったデータを送信しても機能します。 PHP$step_number'2'であることを意味し

、 場合は、以下に示すように、その後、PHPでIF文は動作しないはずです。しかし、それは実行されます!

これは、他のデータがPHPに渡されているときにコードを書き込むための適切な方法だと思いました。

Controller.js

$http.post("../crud/projects_update.php",{ 
    step_number : '1', // This one, I am trying to send, but I don't know whether this is not being sent or the problem is occurred in PHP. 
    project_id : $scope.project_data.project_id // This works in the PHP. It is well sent. 
    project_title : $scope.project_data.project_title 
} 

PHP

require_once 'connect.php'; 
$data = json_decode(file_get_contents("php://input")); 

$step_number = $data->step_number; // This should be received from AngularJS and if the $step_number is not matched in the IF-statement, then the function in { } should not work. 

if ($step_number = '1'){ 
    $project_id = $data->project_id; 
    $project_title = $data->project_title; 
    $conn->query("UPDATE `projects` SET 
    `project_title` = '$project_title',WHERE `project_id` = $project_id") or die(mysqli_error()); 
} 
+0

問題が 'IF($ STEP_NUMBER = '1')としてPHPに思わ{'割り当てない比較です。 ($ step_number == 1){'に変更し、' step_number: '1'、 'step_number:1、'に変更してください。 –

答えて

2

2つのことを変更する必要があります: - step_number : 1,

1.Change

2.Change

if ($step_number = '1'){ //this is assignment not comparison 

に: -

if ($step_number == 1){ // now it's comparison 
+0

コメントありがとうございました!出来た!これが他の人にも役立つことを願っています! :) –

関連する問題