I have 2 dropdown menu. when i click on the first one the second one should display value related to the first choice. however when I select a the first one, i get this.
Error: Unknown column 'abc' in 'where clause'
below is my code. Can some one tell me what i am doing wrong. Thank you in advance.
<?php
include ('db_connect1.php');
$query_parent = mysqli_query($conn, "SELECT * FROM field") or die("Query failed: ".mysqli_error());
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Dependent DropDown List</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#parent_cat").change(function() {
$(this).after('<div id="loader"><img src="img/loading.gif" alt="loading subcategory" /></div>');
$.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
$("#sub_cat").html(data);
$('#loader').slideUp(200, function() {
$(this).remove();
});
});
});
});
</script>
</head>
<body>
<form method="get">
<label for="category">Parent Category</label>
<select name="parent_cat" id="parent_cat">
<?php while($row = mysqli_fetch_array($query_parent)): ?>
<option value="<?php echo $row['field_name']; ?>"><?php echo $row['field_name']; ?></option>
<?php endwhile; ?>
</select>
<br/><br/>
<label>Sub Category</label>
<select name="sub_cat" id="sub_cat"></select>
</form>
</body>
</html>
//loadsubcat.php
<?php
include ('db_connect1.php');
$parent_cat = $_GET['parent_cat'];
$test="SELECT * FROM courses WHERE field_id = {$parent_cat}";
$query = mysqli_query($conn,$test) or die ("Error: ".mysqli_error($conn));
while($row = mysqli_fetch_array($query)) {
echo "<option value='$row[course_id]'>$row[course_name]</option>";
}
?>