如何解决未定义变量:响应?

时间:2019-04-24 06:53:39

标签: php ussd

我正在尝试使我的usdd应用程序正常工作,但我一直遇到

  

未定义变量:响应。

任何帮助将不胜感激。

我已经尝试过在57和75行使用foreach的不同类型的循环。

<?php
    else if ($text == "2"){
        // Business logic for first level response
        $response  = "CON Trade \n";
        $response .= " 5.Withdraw \n";
        $response .= " 6.Deposit \n";

    } else if ($text == "2*5"){ 
        // This is the second level response where the user selected 2 in the 
        first instance 
        $response  = "CON Withdraw \n";
        $response  .=" 7.Tokens \n";    

    } else if($text == "2*5*7"){    
        require "dbconfig/config.php";
        // This is a third level response where the user selected 1 in the 
        first instance
        $response = "CON Tokens \n";
        $tokens   =$_POST["Buy"];

        while($tokens == '$_POST["Buy"]'){
            $balance  =$_POST["balance"];
            $Tokens   = 20000;
            $tokens   = $Tokens - $balance; 
        } 
        //This is a terminal request. Note how we start the response with END
        $response .= "END Your token balance is ".$tokens;

    } else if ($text == "2*6") {
        $response  ="CON Deposit \n";
        $response .= " 8.Quantity";

    } else if($text == "2*6*8") {    
        require "dbconfig/config.php";
        // This is a third level response where the user selected 2 in the 
        second instance
        $response = "CON Quantity \n";
        $quantity =$_POST["sell"]; 

        while($quantity == '$_POST["sell"]'){
            $number1     = 90;
            $number2     = 1.840;
            $number3     = 0.1;
            $Conrate     = $number2 / $number1;
            $result = ($quantity * $Conrate) - ($number3 * ($quantity - 
                $conrate));     

            // This is a terminal request. Note how we start the response with END
            $response .= "END You new token balance is ".$result;
        }
    }
    // Echo the response back to the API
    header('Content-type: text/plain');
    echo $response;
?>

预期的响应,应将在7和8输入的所有数据传递到数据库,并且响应应由ussd生成。

1 个答案:

答案 0 :(得分:1)

在顶部添加$response

您已经在检查中声明了它,并且显然没有一个条件得到满足,这使解释器直接进入导致此异常的最后一个echo调用。