title: Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\test_USSD2\listener.php on line 46
body: <p>I'm trying to select from the database however im getting this error: </p>
  
  <blockquote>
    <p>Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\wamp\www\Project\USSD_Misec\test_USSD2\listener.php on line 46</p>
  </blockquote>
  
  <p>this is my code:</p>
  
  <pre><code>&lt;?php
      include "func/database.php";
  
      //$db = new Database();
      $db =new  Database('localhost', 'username', 'password', 'database_name');
      $db-&gt;connect();
  
  
      $data = file_get_contents("php://input"); 
      $line = "\n-------------------------------------------------------------\n";
      file_put_contents("logs/ussdgw.txt", $data."\n", FILE_APPEND);  
  
      $dataDecoded = json_decode($data);  
  
      $uri = array_reverse(explode("/", $_SERVER["REQUEST_URI"]));
      $usid = $uri[1];
      $action = $uri[0];
  
  
  
      $defaultmenu = array(
          "shouldClose" =&gt; false,
          "ussdMenu" =&gt; "Hello Welcome to Misec..., choose :
          1.Enrolment Enquiry 
          2.Enrolment Date 
  
          3.Exit",
          "responseExitCode" =&gt; 200,
          "responseMessage" =&gt; ""
          );
  
      switch($action)
      {
          case 'response':    
  
                  switch($dataDecoded-&gt;text) 
                  {
                      case 1:
                          $ussdMenu = "1. Enrolment Enquiry";
                          $q = "SELECT * FROM ussd ORDER BY id DESC";
                          $r = $db-&gt;query($q);
                          // if we have a result loop over the result
                          if($db-&gt;num_rows($r) &gt; 0){
                              while($a = $db-&gt;fetch_array_assoc($r)){
  
                                  echo "{$a['id']} wrote $a['name']\n";
  
                              }
  
                          }
                      break;
                      case 2:
                          $ussdMenu = "2. Enrolment Date";
                      break;
                  }   
              $response = array(
                  "shouldClose" =&gt; true,
                  "ussdMenu" =&gt; $ussdMenu,
                  "responseExitCode" =&gt; 200,
                  "responseMessage" =&gt; ""
              );
              $r_encoded = json_encode($response);
              echo $r_encoded;
          break;
  
          case 'status':
              $sessions = file_get_contents("logs/sessions.txt");
                  $sessionsActive = explode("\n", $sessions);
                      if(in_array($usid, $sessionsActive))
                          $sessionActive = true;
                      else 
                          $sessionActive = false;
  
                      $end = array(
                          "sessionActive" =&gt; $sessionActive,
                          "responseExitCode" =&gt; 200,
                          "responseMessage" =&gt; ""
                      );
                  $endEncoded = json_encode($end);
                  echo $endEncoded;   
          break;
  
          case 'start':
              echo json_encode($defaultmenu);
              file_put_contents("logs/sessions.txt", $usid."\n", FILE_APPEND);    
          break;
  
          case 'end':
  
              $sessions = file_get_contents("logs/sessions.txt");
                  $sessionsActive = explode("\n", $sessions);
                      unset($sessionActive[$usid]);
                  $sessionsModified = implode("\n", $sessionActive);
                  file_put_contents("logs/sessions.txt", $sessionsModified); 
  
  
              $end = array(
                  "responseExitCode" =&gt; 200,
                  "responseMessage" =&gt; "Connection ended"
              );
              $endEncoded = json_encode($end);
              echo $endEncoded;
          break;
  }
  </code></pre>