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 8351545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:39:46+00:00 2026-06-09T08:39:46+00:00

I have 2 drop-down lists with different names, and I’m trying to query in

  • 0

I have 2 drop-down lists with different names, and I’m trying to query in just one field.

I’m using a jQuery function wherein if item 1 is selected, the drop-down list 1 will be displayed, and if the item 2 is selected, the drop-down list 2 will be displayed.

This is how I populated my drop-down list from the mysql database and tables:

     <div id="minquep">
       <label>Branch</label>
          <SELECT name="user_min"> 
              <OPTION VALUE="0">Choose a branch
              <?=$minq_options?> 
          </SELECT> 
     </div>
    <div id="albury">
        <label>Branch</label>
          <SELECT name="user_branch"> 
              <OPTION VALUE="0">Choose a branch
              <?=$al_options?> 
          </SELECT> 

And this is how I insert queries into mysql by filling out the form with drop-down lists in it:

if (isset($_REQUEST['Submit'])) { 
$sql = "INSERT INTO $db_table(branch) values ('".mysql_real_escape_string(stripslashes($_REQUEST['user_branch'])).",".mysql_real_escape_string(stripslashes($_REQUEST['user_min']))."')";


if($_REQUEST['user_branch']= ""){

    ($_REQUEST['user_branch']) = NULL;
}


if($result = mysql_query($sql ,$db)) { 
echo '<script type="text/javascript">alert("The user has been added successfully!\n");return true;</script>';
echo "<meta http-equiv=\"refresh\" content=\"0;URL=add_user.php\">";
}

else { 
echo "ERROR: ".mysql_error(); 
} 
}

The testing scenario is that, I choose the value under <select name="user_min">.
So I assume that sql will just bypass the result for user_branch because it is null. But it does prints ‘0’ instead, after the insert query. For example, if the inserted ($_REQUEST['user_min']) value is “Brisbane” and the ($_REQUEST[‘user_branch’]) value is null (because I didn’t selected any value under the user_branch drop-down list), the branch field should just become “Brisbane”, knowing that user_branch is NULL. But it does print “BRISBANE” with 0, like 0, Brisbane in my mysql table.

How can I fix this?

I already tried putting an if condition, it did not work.

if($_REQUEST['user_branch']= ""){

        ($_REQUEST['user_branch']) = NULL;
    }

I’ve also tried changing the user_min into same name user_branch, but it does not get the selected value, instead of Brisbane it just prints ‘0’

  • 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-06-09T08:39:47+00:00Added an answer on June 9, 2026 at 8:39 am

    A few things –

    1. you are setting user_branch = NULL after the $sql.

    2. You are using quotes around value. It’s fine non-Null values -you need to check if there is NULL value then don’t use quotes in your $sql.

    3. You are using single “=” in your IF statement. This is failing your If statement. Change it to if($var == '')

    Update

    Some suggestions based on your existing code – however there are other best practices to achieve what you are trying to achieve….

    $user_branch =  $_REQUEST['user_branch'];
    $user_min =  $_REQUEST['user_min']; 
    //you should validate above values first 
    
    if$user_branch == "" || $user_min == "") {
        $db_value = "NULL"; 
    } else 
    {
    $db_value = "'".mysql_real_escape_string(stripslashes($user_branch.','.$user_min))."'";
    }
    
    
    $sql = "INSERT INTO $db_table(branch) values (".$db_value.")";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implenmented drop-down lists Select menus in jQuery Mobile. <div data-role=fieldcontain> <label for=name
I want to have a drop down box that has a list of different
I have three cascaded drop down lists. ddlIllnessType, ddlIllnessSubType and ddlInfectiousAgent Initially, only ddlIllnessType
I have a user control in a master page with two drop down lists.
I have one drop down list in my page, which contains two options. What
I have a drop-down list which is generated based on the following sql query:
I have two drop down lists: <select name="branch"> <option value="b">Blacksburg</option> <option value="c">Christiansburg</option> <option value="f">Floyd</option>
I have a mutliple drop down menus that I am using to hide/show rows
I have a drop down list that list different options to the user. I
I have a situation where I have multiple drop down lists that are hidden

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.