0

I'm trying to get my ussd application to work but I keep on running into

Undefined variable: response.

Any help would be appreciated.

I've tried using different types of loops foreach and while at line 57 and 75.

<?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;
?>

The expected response, all data entered at 7 & 8 should be passed to a database and a response should be generated by the ussd.

Igor Ilic
  • 1,370
  • 1
  • 11
  • 21
  • 1
    Your `$response` variable is not getting set. Add `response = '';` in the very beginning. – Pupil Apr 24 '19 at 06:54

1 Answers1

1

add $response at the top.

You have declared it within the checks and apparently none of the conditions is satisfied which brings the interpreter directly to the last echo call which causes this exception.

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78