Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!