Foros del Web » Programando para Internet » PHP »

Problemas con array

Estas en el tema de Problemas con array en el foro de PHP en Foros del Web. Hola chicos como estan, tengo un problema haber si alguien me puede ayudar. Tengo ese codigo en php $preference_data = array( "items" => array( array( ...
  #1 (permalink)  
Antiguo 09/11/2017, 09:39
 
Fecha de Ingreso: febrero-2007
Mensajes: 12
Antigüedad: 17 años, 2 meses
Puntos: 0
Problemas con array

Hola chicos como estan, tengo un problema haber si alguien me puede ayudar.
Tengo ese codigo en php

$preference_data = array(
"items" => array(
array(
"title" => "Pago de Producto",
"currency_id" => "ARG",
"category_id" => "Category",
"quantity" => 1,
"unit_price" => 590)
//"unit_price" => $PrecioItem )
)
);

necesito que donde dice 590 sea una variable y no me lo toma de ninguna manera, alguien sabe como hacer para que en unit_price me tome una variable.

Gracias
  #2 (permalink)  
Antiguo 09/11/2017, 16:20
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 9 meses
Puntos: 379
Respuesta: Problemas con array

Y si publicas el código con el problema para saber que estas haciendo ?
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #3 (permalink)  
Antiguo 10/11/2017, 08:27
 
Fecha de Ingreso: febrero-2007
Mensajes: 12
Antigüedad: 17 años, 2 meses
Puntos: 0
Respuesta: Problemas con array

Hola chicos, aca les dejo el codigo completo por si alguien me puede ayudar, ese es todo el codigo, no me permite la variable $PrecioItem en unit_price ya se me quemaron los libros.

Código PHP:
Ver original
  1. <?php
  2. require_once "mercadopago.php";
  3.  
  4. $mp = new MP("*****", "*****");
  5. $PrecioItem=$_GET['PrecioItem'];
  6. //$PrecioItem = isset($_POST['PrecioItem']) ? $_POST['PrecioItem'] : NULL;
  7.  
  8.  
  9.     $preference_data = array(
  10.     "items" => array(
  11.         array(
  12.             "title" => "Pago de Producto",
  13.             "currency_id" => "ARG",
  14.             "category_id" => "Category",
  15.             "quantity" => 1,
  16.             //"unit_price" => 590)
  17.             "unit_price" => $PrecioItem)
  18.     )
  19. );
  20. $preference = $mp->create_preference($preference_data);
  21. echo $PrecioItem;
  22. ?>
  23. <!doctype html>
  24. <html>
  25.     <head>
  26.         <title>MercadoPago SDK - Create Preference and Show Checkout Example</title>
  27.     </head>
  28.     <body>
  29.    
  30.  
  31.         <form name="form1" method="post" action="">
  32.      
  33.         <input name="PrecioItem" type="text" id="PrecioItem" />
  34.         <a href="<?php echo $preference["response"]["init_point"]; ?>" name="MP-Checkout" class="orange-ar-m-sq-arall">Pagar</a>
  35.         <script type="text/javascript" src="http://mp-tools.mlstatic.com/buttons/render.js"></script>
  36.         </form>
  37.  
  38.  
  39. </body>
  40. </html>

sale el error:
Fatal error: Uncaught exception 'Exception' with message 'unit_price needed' in /home/mass2014mass/public_html/mercadopago/mercadopago.php:419 Stack trace: #0 /home/mass2014mass/public_html/mercadopago/mercadopago.php(432): MPRestClient::exec('POST', '/checkout/prefe...', Array, 'application/jso...') #1 /home/mass2014mass/public_html/mercadopago/mercadopago.php(177): MPRestClient::post('/checkout/prefe...', Array) #2 /home/mass2014mass/public_html/mercadopago/button.php(20): MP->create_preference(Array) #3 {main} thrown in /home/mass2014mass/public_html/mercadopago/mercadopago.php on line 419

Sin embargo yo hago una comprobacion con la variable $PrecioItem y si me trae el valor.

Gracias a todos de antemano

Última edición por Triby; 10/11/2017 a las 19:04 Razón: Código en Highlight y eliminar posibles datos privados.

Etiquetas: variable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:13.