Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 849159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:03:42+00:00 2026-05-15T07:03:42+00:00

I have a PHP form. The form works but I’m trying to test to

  • 0

I have a PHP form. The form works but I’m trying to test to see if a value other than the first item has been selected. I can’t figure out how to write the If statement.

$products = array(
 '' => 1,
 'Item 2' => 2,
 'Item 3' => 3,
 'Item 4' => 4,
 'Item 5' => 5,
 'Item 6' => 6
);

$html = generateSelect('products', $products);

function generateSelect($name = '', $options = array()) {
 $html = '<select name="'.$name.'">';
 foreach ($options as $option => $value) {
  $html .= '<option value='.$value.'>'.$option.'</option>';
 }
 $html .= '</select>';
 return $html;
}

In my table, the drop down box is displayed:

<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:center; padding:{$cell_padding}; font-weight:bold; {$product[3]}">{$product[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><select name="{$product[1]}">
 <option value="1"></option>
 <option value="2">Item 2</option>
 <option value="3">Item 3</option>
 <option value="4">Item 4</option>
 <option value="5">Item 5</option>
 <option value="6">Item 6</option>
</select></td>
</tr>

I use the following if statement to check to see if someone has entered a phone number. if they have not entered a phone number, then the “Phone:” text turns red. How do I do an if statement similar to this to verify that someone has selected a product option from the drop down box?

  if(!empty($_POST['phone'])) {
   $phone[2] = clean_var($_POST['phone']);
   if (function_exists('htmlspecialchars')) $phone[2] = htmlspecialchars($phone[2], ENT_QUOTES);
  }
  else {
    $error = 1;
    $phone[3] = 'color:#d20128;';
  } 

it seems simple but I can’t figure it out.

EDIT 1:

I tried the suggestions, and the following works best so far:

if ($_POST['product'] != 1){

after I click the ‘submit’ button. the “Product:” text does turn red like expected; however, the drop down box resets to showing the option value 1 but the variable still remains at the selected value.

long questions short. how do I tell the dropdown box to show, for example, item 5?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:03:42+00:00Added an answer on May 15, 2026 at 7:03 am

    If I understand correctly, wouldn’t this meet your needs?

    if ($_POST['product'] != 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have 4 pages. They are very simple. index.php (WORKS) <html> <form action=upload.php
I have a php form that has a known number of columns (ex. top
I have a form which has a select tag; on selection of an item
I have a php file which has one form and 2 submit buttons, onclick
I have to post to a URL using PHP. right now it works but
I have coded in PHP but today for the first time I needed to
If I have the following code before </head> the php form sends but the
I have a php contact form which all works well with its validation etc,
I'm trying to edit a php contact form script, but I can't find where
I have an image upload form and it works fine. But underneath that same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.