Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda