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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:34:54+00:00 2026-05-31T08:34:54+00:00

Alright then I’m having an issue when trying to fill a dropdown with MySQL

  • 0

Alright then I’m having an issue when trying to fill a dropdown with MySQL information. The problem occurs when on the second dropdown I try to get information from things with apostrophes… such as women’s clothing or men’s clothing. Any help with be greatly appreciated.

Here is the error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘s Clothing” at line 1

Here is the code.

<?php
//**************************************
//     Page load dropdown results     //
//**************************************
function getTierOne()
{
    $catresult = mysql_query("SELECT DISTINCT category FROM categories") 
    or die(mysql_error());

      while($tier = mysql_fetch_array( $catresult )) 

        {
           echo '<option value="'.$tier['category'].'">'.$tier['category'].'</option>';
        }

}

//**************************************
//     First selection results     //
//**************************************
if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
   drop_1($_GET['drop_var']); 
}

function drop_1($drop_var)
{  
    include_once('db.php');
    $result = mysql_query("SELECT DISTINCT level1 FROM categories WHERE category='$drop_var'") 
    or die(mysql_error());

    echo '<select name="drop_2" id="drop_2">
          <option value=" " disabled="disabled" selected="selected">Choose one</option>';

           while($drop_2 = mysql_fetch_array( $result )) 
            {
              echo '<option value="'.$drop_2['level1'].'">'.$drop_2['level1'].'</option>';
            }

    echo '</select>';
    echo "<script type=\"text/javascript\">
$('#wait_2').hide();
    $('#drop_2').change(function(){
      $('#wait_2').show();
      $('#result_2').hide();
      $.get(\"pla2.php\", {
        func: \"drop_2\",
        drop_var: $('#drop_2').val()
      }, function(response){
        $('#result_2').fadeOut();
        setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
      });
        return false;
    });
</script>";
}


//**************************************
//     Second selection results     //
//**************************************
if($_GET['func'] == "drop_2" && isset($_GET['func'])) { 
   drop_2($_GET['drop_var']); 
}

function drop_2($drop_var)
{  
    include_once('db.php');
    $bresult = mysql_query("SELECT DISTINCT level2 FROM categories WHERE level1='$drop_var'") 
    or die(mysql_error());

    echo '<select name="drop_3" id="drop_3">
          <option value=" " disabled="disabled" selected="selected">Choose one</option>';

           while($drop_3 = mysql_fetch_array( $bresult )) 
            {
              echo '<option value="'.$drop_3['level2'].'">'.$drop_3['level2'].'</option>';
            }

    echo '</select> ';
    echo '<input type="submit" name="submit" value="Submit" />';
}
?>
  • 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-31T08:34:55+00:00Added an answer on May 31, 2026 at 8:34 am

    I figured it out. I had to change the

    "SELECT DISTINCT level2 FROM categories WHERE level1='$drop_var'"

    to

    "SELECT DISTINCT level2 FROM categories WHERE level1='".mysql_real_escape_string$drop_var"'"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I'm trying to read a comma delimited file and then put that into
Alright. The problem we're having is that we have NSStrings filled with dates in
Alright, so I'm trying to cap my framerate at 60 frames per second, but
alright so I am trying to read a text file. and then split it
Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright, well this is the deal. I have a page, and then it loads
Alright so I want to grab the information on a website thats between [usernames]
Alright I've been creating some test code to try and clear the upload queue,
Alright so we had a problem recently In reporting services some of the String

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.