I fail in a project of a course that I am doing

0

Hello very good I am doing a project and I have found this error:

  

Notice: Undefined index: registration in   D: \ xampp \ htdocs \ gdlwebcamp \ validate_register.php on line 25

     

Warning: Invalid argument supplied for foreach () in   D: \ xampp \ htdocs \ gdlwebcamp \ includes \ functions \ functions.php on line 29        string (20) "{" full_pass ": 50}"        string (2) "[]"

This is the error that throws me and I can not find what is the fault I have. My code is as follows:

In this first one that I introduce, it is the error of line 23 that I have underlined so that it is easier to find:

<?php include_once 'includes/templates/header.php'; ?>
<section class="seccion contenedor">
        <h2>Resumen Registro</h2>

    <?php if(isset($_POST['submit'])):  /*Esto es para asegurarnkos que la variable submit existe*/

    $nombre = $_POST['nombre'];
    $apellido = $_POST['apellido'];
    $email = $_POST['email'];
    $regalo = $_POST['regalo'];
    $total = $_POST['total_pedido'];
    $fecha = date('Y-m-d H:i:s');

    // Pedidos
    $boletos = $_POST['boletos'];
    $camisas = $_POST['pedido_camisas'];
    $etiquetas = $_POST['pedido_etiquetas']; //Lo que hare es coger estas tres y pasarla a una funcion que me regresara como Jason que estara en funciones.php
    include_once 'includes/funciones/funciones.php';
    $pedido = productos_json($boletos, $camisas, $etiquetas);

    //eventos
    $eventos = $_POST['registro'];
    $registro = eventos_json($eventos);
    ?>

     <pre>
    <?php var_dump($pedido); ?>
    </pre>

    <hr>

    <pre>
    <?php var_dump($registro); ?>
    </pre>

     <?php endif;/*Cierre del if para revisar el submit*/ ?>

Exactly line 23 is $eventos = $_POST['registro'];

And the second warning that is a warning the code is this:

<?php 
function productos_json(&$boletos, &$camisas = 0, &$etiquetas = 0){ 

    $dias = array(0 => 'un_dia', 1=> 'pase_completo', 2=> 'pase_2dias');
    $total_boletos = array_combine($dias, $boletos);   
    $json = array();
    foreach($total_boletos as $key => $boletos):
            if((int) $boletos > 0):
                $json[$key] = (int) $boletos;
            endif ;   
    endforeach;

    $camisas = (int) $camisas;
    if($camisas > 0):
        $json['camisas'] = $camisas;
    endif;

    $etiquetas = (int) $etiquetas;
    if($etiquetas > 0):
        $json['etiquetas'] = $etiquetas;
    endif;

    return json_encode($json);
}

function eventos_json(&$eventos) {
    $eventos_json = array(); 
    foreach($eventos as $evento):
    $eventos_json['eventos'] [] = $evento;
endforeach;

return json_encode($eventos_json); /
}

And line 29 is this foreach($eventos as $evento):

I have checked the code several times to find some syntax error but I have not found anything, I've been stuck here for two days without getting a solution. Your collaboration would be very helpful, thank you very much in advance for everything.

I subtract the information from a file called registro.php, the code is this:

<?php include_once 'includes/templates/header.php'; ?>

    <section class="seccion contenedor">
        <h2>Registro de Usuarios</h2>
        <form id="registro" class="registro" action="validar_registro.php" method="post"> 
        <div id="datos_usuario" class="registro caja clearfix"> 
            <div class="campo">
                <label for="nombre"><span>*</span>Nombre:</label>
                <input type="text" id="nombre" name="nombre" placeholder="Tu Nombre">
            </div>
            <div class="campo">
                    <label for="apellido"><span>*</span>Apellido:</label>
                    <input type="text" id="apellido" name="apellido" placeholder="Tu Apellido">
                </div>
            <div class="campo">
                    <label for="email"><span>*</span>Email:</label>
                    <input type="text" id="email" name="email" placeholder="Tu Email">
                </div>
            <div id="error"></div>
        </div><!--.#datos_usuarios-->

        <div id="paquetes" class="paquetes">
            <h3>Elige el número de boletos</h3>
            <ul class="lista-precios clearfix">
                    <li>
                        <div class="tabla-precio">
                            <h3>Pase por día (viernes)</h3>
                            <p class="numero">30€</p>
                            <ul>
                                <li>Bocadillos Gratis</li>
                                <li>Todas las Conferencias</li>
                                <li>Todos los talleres</li>
                            </ul>
                            <div class="orden">
                                    <label for="pase_dia">Boletos deseados:</label>
                                    <input type="number" min="0" id="pase_dia" size="3" name="boletos[]" placeholder="0">
                                </div>
                        </div>
                    </li>
                    <li>
                         <div class="tabla-precio">
                            <h3>Todos los días</h3>
                            <p class="numero">50€</p>
                            <ul>
                                 <li>Bocadillos Gratis</li>
                                 <li>Todas las Conferencias</li>
                                 <li>Todos los talleres</li>
                            </ul>
                            <div class="orden">
                                    <label for="pase_completo">Boletos deseados:</label>
                                    <input type="number" min="0" id="pase_completo" size="3" name="boletos[]" placeholder="0">
                                </div>

                     </li>
                     <li>
                             <div class="tabla-precio">
                                <h3>Pase por 2 días (viernes y sábado)</h3>
                                <p class="numero">45€</p>
                                <ul>
                                     <li>Bocadillos Gratis</li>
                                     <li>Todas las Conferencias</li>
                                     <li>Todos los talleres</li>
                                </ul>
                                <div class="orden">
                                        <label for="pase_dosdias">Boletos deseados:</label>
                                        <input type="number" min="0" id="pase_dosdias" size="3" name="boletos[]" placeholder="0">
                                    </div>
                             </div>
                     </li>
                </ul>
        </div><!--.#paquetes-->

        <div id="eventos" class="eventos clearfix"> 
                <h3>Elige tus talleres</h3>
                <div class="caja">
                      <div id="viernes" class="contenido-dia clearfix">
                          <h4>Viernes</h4>
                              <div>
                                  <p>Talleres:</p>
                                  <label><input type="checkbox" name="registro[]" id="taller_01" value="taller_01"><time>10:00</time> Responsive Web Design</label>
                                  <label><input type="checkbox" name="registro[]" id="taller_02" value="taller_02"><time>12:00</time> Flexbox</label>
                                  <label><input type="checkbox" name="registro[]" id="taller_03" value="taller_03"><time>14:00</time> HTML5 y CSS3</label>
                                  <label><input type="checkbox" name="registro[]" id="taller_04" value="taller_04"><time>17:00</time> Drupal</label>
                                  <label><input type="checkbox" name="registro[]" id="taller_05" value="taller_05"><time>19:00</time> WordPress</label>
                              </div>
                              <div>
                                  <p>Conferencias:</p>
                                  <label><input type="checkbox" name="registro[]" id="conf_01" value="conf_01"><time>10:00</time> Como ser Freelancer</label>
                                  <label><input type="checkbox" name="registro[]" id="conf_02" value="conf_02"><time>17:00</time> Tecnologías del Futuro</label>
                                  <label><input type="checkbox" name="registro[]" id="conf_03" value="conf_03"><time>19:00</time> Seguridad en la Web</label>
                              </div>
                              <div>
                                  <p>Seminarios:</p>
                                  <label><input type="checkbox" name="registro[]" id="sem_01" value="sem_01"><time>10:00</time> Diseño UI y UX para móviles</label>
                              </div>
                      </div> <!--#viernes-->
                      <div id="sabado" class="contenido-dia clearfix">
                          <h4>Sábado</h4>
                          <div>
                                <p>Talleres:</p>
                                <label><input type="checkbox" name="registro[]" id="taller_06" value="taller_06"><time>10:00</time> AngularJS</label>
                                <label><input type="checkbox" name="registro[]" id="taller_07" value="taller_07"><time>12:00</time> PHP y MySQL</label>
                                <label><input type="checkbox" name="registro[]" id="taller_08" value="taller_08"><time>14:00</time> JavaScript Avanzado</label>
                                <label><input type="checkbox" name="registro[]" id="taller_09" value="taller_09"><time>17:00</time> SEO en Google</label>
                                <label><input type="checkbox" name="registro[]" id="taller_10" value="taller_10"><time>19:00</time> De Photoshop a HTML5 y CSS3</label>
                                <label><input type="checkbox" name="registro[]" id="taller_11" value="taller_11"><time>21:00</time> PHP Medio y Avanzado</label>
                          </div>
                          <div>
                                <p>Conferencias:</p>
                                <label><input type="checkbox" name="registro[]" id="conf_04" value="conf_04"><time>10:00</time> Como crear una tienda online que venda millones en pocos días</label>
                                <label><input type="checkbox" name="registro[]" id="conf_05" value="conf_05"><time>17:00</time> Los mejores lugares para encontrar trabajo</label>
                                <label><input type="checkbox" name="registro[]" id="conf_06" value="conf_06"><time>19:00</time> Pasos para crear un negocio rentable</label>
                          </div>
                          <div>
                                <p>Seminarios:</p>
                                <label><input type="checkbox" name="registro[]" id="sem_02" value="sem_02"><time>10:00</time> Aprende a Programar en una mañana</label>
                                <label><input type="checkbox" name="registro[]" id="sem_03" value="sem_03"><time>17:00</time> Diseño UI y UX para móviles</label>
                          </div>
                      </div> <!--#sabado-->
                      <div id="domingo" class="contenido-dia clearfix">
                          <h4>Domingo</h4>
                          <div>
                                <p>Talleres:</p>
                                <label><input type="checkbox" name="registro[]" id="taller_12" value="taller_12"><time>10:00</time> Laravel</label>
                                <label><input type="checkbox" name="registro[]" id="taller_13" value="taller_13"><time>12:00</time> Crea tu propia API</label>
                                <label><input type="checkbox" name="registro[]" id="taller_14" value="taller_14"><time>14:00</time> JavaScript y jQuery</label>
                                <label><input type="checkbox" name="registro[]" id="taller_15" value="taller_15"><time>17:00</time> Creando Plantillas para WordPress</label>
                                <label><input type="checkbox" name="registro[]" id="taller_16" value="taller_16"><time>19:00</time> Tiendas Virtuales en Magento</label>
                          </div>
                          <div>
                                <p>Conferencias:</p>
                                <label><input type="checkbox" name="registro[]" id="conf_07" value="conf_07"><time>10:00</time> Como hacer Marketing en línea</label>
                                <label><input type="checkbox" name="registro[]" id="conf_08" value="conf_08"><time>17:00</time> ¿Con que lenguaje debo empezar?</label>
                                <label><input type="checkbox" name="registro[]" id="conf_09" value="conf_09"><time>19:00</time> Frameworks y librerias Open Source</label>
                          </div>
                          <div>
                                <p>Seminarios:</p>
                                <label><input type="checkbox" name="registro[]" id="sem_04" value="sem_04"><time>14:00</time> Creando una App en Android en una tarde</label>
                                <label><input type="checkbox" name="registro[]" id="sem_05" value="sem_05"><time>17:00</time> Creando una App en iOS en una tarde</label>
                          </div>
                      </div> <!--#domingo-->
                  </div><!--.caja-->
            </div> <!--#eventos-->

            <div id="resumen" class="resumen clearfix">
                <h3>Pago y extras</h3>
                <div class="caja clearfix">
                    <div class="extras">
                        <div class="orden">
                            <label for="camisa_evento">Camisa del evento 10€<small>(promocion 7% dto.)</small></label>
                            <input type="number" min="0" id="camisa_evento" name="pedido_camisas" size="3" placeholder="0">
                        </div><!--.orden-->
                        <div class="orden">
                            <label for="etiquetas">Paquete de 10 etiquetas 2€<small>(HTML5, CSS3, JavaScript, Chrome)</small></label>
                            <input type="number" min="0" id="etiquetas" name="pedido_etiquetas" size="3" placeholder="0">
                        </div><!--.orden-->
                        <div class="orden">
                            <label for="regalo">Seleccione un regalo</label><br>
                            <select id="regalo" name="regalo" required>
                                <option value="">-Seleccione un regalo--</option><!--.Esto sera despues modificado con JavaScript para que seleccione y elija un regalo-->
                                <option value="2">Etiquetas</option>
                                <option value="1">Pulseras</option>
                                <option value="3">Plumas</option>
                            </select>
                        </div><!--.orden-->
                        <input type="button" id="calcular" class="button" value="Calcular">
                    </div><!--.extras-->

                    <div class="total">
                        <p>Resumen:</p>
                        <div id="lista_productos">

                        </div>
                        <p>Total:</p>
                        <div id="suma-total">

                        </div>
                        <input type="hidden" name="total_pedido" id="total_pedido">
                        <input id="btnRegistro" type="submit" name="submit" class="button" value="Pagar">
                    </div><!--.caja-->
                </div><!--#resumen-->
            </div>

        </form>

    </section>

   <?php include_once 'includes/templates/footer.php'; ?>

I think this is where the ruling has to be because if I'm not mistaken, it does not take the information from another side.

I have entered the <?php print_r($_POST); die ?> in this way in the code:

<?php include_once 'includes/templates/header.php'; ?>
 <?php print_r($_POST); die ?>

    <section class="seccion contenedor">
        <h2>Registro de Usuarios</h2>

Below that h2 comes the rest of the code that I put before you but not to get so dizzy I have omitted it in this comment. Well to put the <?php print_r($_POST); die ?> , I do not know if it will be ok because it is the first time I use it (sorry), it has returned an empty array and the page does not leave me nothing but the <?php include_once 'includes/templates/header.php'; ?> with its respective characteristics what I gave him with css. Postscript sorry for the delay in responding, but they are doing work in my house and the fatal Internet is going.

I have echoed as you said in the last comment and when filling out the form, you have given me this on the following page:

  

Notice: Undefined index: registration in   D: \ xampp \ htdocs \ gdlwebcamp \ validate_register.php on line 23

     

Warning: Invalid argument supplied for foreach () in > D: \ xampp \ htdocs \ gdlwebcamp \ includes \ functions \ functions.php on line 29   string (39) "{" un_dia ": 2," shirts ": 5," tags ": 10}"   string (2) "[]"

It gives me exactly the same as in the course except with the error that I get that in the course does not leave any of that.

    
asked by Manuel 17.05.2018 в 13:05
source

1 answer

2

You do not have any syntax errors.

  

Notice: Undefined index: record in D: \ xampp \ htdocs \ gdlwebcamp \ validate_register.php on line 25

You are saying that there is no value in the $ _POST variable in the 'record' index. After that, the second fault:

  

Warning: Invalid argument supplied for foreach () in D: \ xampp \ htdocs \ gdlwebcamp \ includes \ functions \ functions.php on line 29

It's because $ events is empty due to the first failure.

Check your form well and see that the name 'record' is registered in the input from which you want to take the information. Greetings.

    
answered by 17.05.2018 в 13:11