2017-08-28 48 views
0

我剛開始使用restful web服務。REST Ful服務錯誤「調用未定義的函數deliver_response()」

我得到一個錯誤「調用未定義函數deliver_response()」請幫我解決這個問題或給我提醒。 函數調用不起作用,我是寧靜的Web服務的新手,在進入寧靜的Web服務之前,我想知道爲什麼這個函數調用不起作用。

我有得分= 400級= 4 [email protected]

//rest.php 

<?php 
include "..\dbconn.php"; 
include "rest_function.php"; 
$gamer_details = array(); 

if(!empty($_GET['gamer_id'])){ 
echo $id = $_GET['gamer_id']; 

$gamer_details = get_gamer_details($id); 
//print_r($gamer_details); 


if(!empty($gamer_details)){ 

     $score = $gamer_details['score']; 
     $level = $gamer_details['level']; 
     $gamer_id = $gamer_details['gamer_id']; 

     deliver_response($score,$level,$gamer_id); 

    }else{ 
     echo "failed"; 
     } 

     function deliver_response($score,$level,$gamer_id){ 

      header('HTTP/1.1 $score $level $gamer_id'); 
      $response_value['score']=$score; 
      $response_value['level']=$level; 
      $response_value['gamer_id']=$gamer_id; 
      $json_response = json_encode($response_value); 
      echo $json_response; 
     } 

} 


?> 
+0

將函數進一步移到文件上方。 – flauntster

+0

或者畢竟'if's –

回答

0

你實現它之前,您使用 「deliver_response」 的值。在使用之前執行此功能:

<?php 
include "..\dbconn.php"; 
include "rest_function.php"; 

$gamer_details = array(); 

function deliver_response($score,$level,$gamer_id){ 
    header('HTTP/1.1 $score $level $gamer_id'); 
    $response_value['score']=$score; 
    $response_value['level']=$level; 
    $response_value['gamer_id']=$gamer_id; 
    $json_response = json_encode($response_value); 
    echo $json_response; 
} 

if(!empty($_GET['gamer_id'])){ 
    echo $id = $_GET['gamer_id']; 

    $gamer_details = get_gamer_details($id); 
    //print_r($gamer_details); 
    if(!empty($gamer_details)){ 
     $score = $gamer_details['score']; 
     $level = $gamer_details['level']; 
     $gamer_id = $gamer_details['gamer_id']; 
     deliver_response($score,$level,$gamer_id); 
    } else { 
     echo "failed"; 
    } 
} 
?> 
相關問題