Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/07/2015, 11:01
jfloresga
 
Fecha de Ingreso: enero-2014
Mensajes: 17
Antigüedad: 10 años, 3 meses
Puntos: 0
Error unexpected T_STRING, expecting T_FUNCTION

Hola

Soy nuevo en PHP, estoy haciendo una aplicación móvil que envía un JSON a un programa PHP en el hostting para que inserte la información contenida en el JSON, obtengo como error lo escrito en el título de este tema, me puede ayudar de favor ? que tengo mal?

Código PHP:
Ver original
  1. <?php
  2. function getStatusCodeMessage($status)
  3. {
  4.  
  5.     $codes = Array(
  6.         100 => 'Continue',
  7.         101 => 'Switching Protocols',
  8.         200 => 'OK',
  9.         201 => 'Created',
  10.         202 => 'Accepted',
  11.         203 => 'Non-Authoritative Information',
  12.         204 => 'No Content',
  13.         205 => 'Reset Content',
  14.         206 => 'Partial Content',
  15.         300 => 'Multiple Choices',
  16.         301 => 'Moved Permanently',
  17.         302 => 'Found',
  18.         303 => 'See Other',
  19.         304 => 'Not Modified',
  20.         305 => 'Use Proxy',
  21.         306 => '(Unused)',
  22.         307 => 'Temporary Redirect',
  23.         400 => 'Bad Request',
  24.         401 => 'Unauthorized',
  25.         402 => 'Payment Required',
  26.         403 => 'Forbidden',
  27.         404 => 'Not Found',
  28.         405 => 'Method Not Allowed',
  29.         406 => 'Not Acceptable',
  30.         407 => 'Proxy Authentication Required',
  31.         408 => 'Request Timeout',
  32.         409 => 'Conflict',
  33.         410 => 'Gone',
  34.         411 => 'Length Required',
  35.         412 => 'Precondition Failed',
  36.         413 => 'Request Entity Too Large',
  37.         414 => 'Request-URI Too Long',
  38.         415 => 'Unsupported Media Type',
  39.         416 => 'Requested Range Not Satisfiable',
  40.         417 => 'Expectation Failed',
  41.         500 => 'Internal Server Error',
  42.         501 => 'Not Implemented',
  43.         502 => 'Bad Gateway',
  44.         503 => 'Service Unavailable',
  45.         504 => 'Gateway Timeout',
  46.         505 => 'HTTP Version Not Supported'
  47.     );
  48.  
  49.     return (isset($codes[$status])) ? $codes[$status] : '';
  50. }
  51.  
  52. // Helper method to send a HTTP response code/message
  53. function sendResponse($status = 200, $body = '', $content_type = 'text/html')
  54. {
  55.     $status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status);
  56.     header($status_header);
  57.     header('Content-type: ' . $content_type);
  58.     echo $body;
  59. }
  60.  
  61. class RedeemAPI {
  62.     private $db;
  63.     // Constructor - open DB connection
  64.     function __construct() {
  65.         $this->db = new mysqli('localhost', 'futchoco_admin', 'Futcho190867', 'futchoco_futsoft');
  66.        /* verificar la conexión */
  67.        if (mysqli_connect_errno()) {
  68.         printf("Conexión fallida: %s\n", mysqli_connect_error());
  69.         exit();
  70.       }
  71.         $this->db->autocommit(FALSE);
  72.     }
  73.        
  74.     // Destructor - close DB connection
  75.     function __destruct() {
  76.         $this->db->close();
  77.     }
  78.     // Main method to redeem a code
  79.     function redeem() {
  80.     // Check for required parameters
  81.         $json = file_get_contents('php://input');
  82.         $obj = json_decode($json,true);
  83.         echo $obj;
  84.         $rows = array();
  85.         //foreach($array[] as $key => $value)
  86.         foreach($obj as $item)
  87.         {
  88.             $rows[] = "('" . $key . "', '" . $value . "')";
  89.             $stmt = $this->db->prepare('INSERT INTO prueba (id,nombre)
  90.                                         VALUES (%d,%s)',$item->id_cliente,$item->nombre) or die(mysqli_error($this->db));
  91.             $stmt->execute();
  92.         }
  93.     }
  94.     sendResponse(400, 'Invalid request');
  95.     return false;
  96.   }
  97. }
  98.  
  99.  
  100. // This is the first thing that gets called when this page is loaded
  101. // Creates a new instance of the RedeemAPI class and calls the redeem method
  102. $api = new RedeemAPI;
  103. $api->redeem();
  104.  
  105. ?>

Última edición por Triby; 29/07/2015 a las 01:37 Razón: Código en highlight