Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
PHP switch always chooses last option

My PHP switch always chooses the last option. Even if I choose the the first option, my code will only execute the last option. How can I manage that it picks the option I choose?

Website:

Website

CODE:

<select name='auto-listings-package' id='auto-listings-package' class='auto-listings-package'>

                <?php foreach ( $packages as $package_id => $package ) : ?>

                    <option value="<?php echo esc_attr( $package_id ); ?>" data-price="<?php echo esc_attr( auto_listings_raw_price( $package['price'] ) ); ?>"><?php echo wp_kses_post( $package['label'] ) ?></option>

                    <?php
                        if(isset($_POST['auto-listings-purchase'])) {
                            
                            if($package_id == '2823') {
                                wp_redirect('https://www.google.com');
                            } elseif ($package_id == '2633') {
                                wp_redirect('https://www.helemaaldebom.nl');
                            } else {
                                echo 'Something went wrong. Please contact our staff.';
                            }

                        }
                    ?>

                <?php endforeach; ?>

            </select>

HTML

HTML

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Solved it. I forgot to fill the $package variable with the input of the user. I have put this before the if-statement and now it works.

$package_id = $_POST['auto-listings-package'];
over 4 years ago · Santiago Trujillo Denunciar

0

change the default to following

default:
                echo "-".$p.'- Something went wrong. Please contact our staff.';

and see the output.

that will help you to see why it does not match the condition (you might be getting spaces).

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda