Question about dd.php

I am trying to create a query form where first dropdown box is the State and the second dropdown is the County.

When it searches my state & counties table, it uses the 'fips_code' and that is working correctly. However, my contacts table does not have an 'fips_code' to search with. I actually need to get the value of my 'state_abb' and pass that along with my $_POST.

How would I go about doing this ??
My current code goes as follows:
// username and password to log onto db server
// name of database

////// DONOT EDIT BELOW /////////

function connecttodb($servername,$dbname,$dbuser,$dbpassword)
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
//////// End of connecting to database ////////

<!doctype html public "-//w3c//dtd html 3.2//en">


<link type="text/css" href="css/jquery-ui-1.8rc3.custom.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src=""></script>
<script src=""></script>
<script type="text/javascript">
$(function() {

// Clear values on refresh

$("#zip_code").attr('disabled', true);

source: "industry.php",
minLength: 2,
select: function(event, ui) {

source: "states_abbrev.php",
minLength: 2,
select: function(event, ui){
$("#zip_code").attr('disabled', false);

change: function(event, ui){
secondary_url = "zips.php?filter=" + ui.item.stfips;
$("#zip_code").autocomplete("option", "source", secondary_url);
source: "",
minLength: 2,
select: function(event,ui){
<title>Search for a prospect in your area</title>

<SCRIPT language=JavaScript>

function reload(form)
self.location='search_sic.php?cat=' + val ;


If register_global is off in your server then after reloading of the page to get the value of cat from query string we have to take special care.
To read more on register_global visit.
@$cat=$_GET['cat']; // Use this line or below line if register_global is off
if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not.
echo "Data Error";

//@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT state_name,state_abb,fips_code FROM smf_fips_states ORDER by fips_code");

///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT county_name FROM smf_fips_counties where state_fips=$cat order by county_name");
}else{$quer=mysql_query("SELECT DISTINCT county_name FROM smf_fips_counties order by county_name"); }
////////// end of query for second subcategory drop down list box ///////////////////////////

echo "<form method=post name=f1 action='dd-check.php'>";
/// Add your form processing page address to action in above line. Example action=dd-check.php////

////////// Starting of first drop downlist /////////

echo "State: <select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['fips_code']==@$cat){echo "<option selected value='$noticia2[fips_code]'>$noticia2[state_name]</option>"."<BR>";}
else{echo "<option value='$noticia2[fips_code]'>$noticia2[state_name]</option>";}
echo "</select>";

////////////////// This will end the first drop down list ///////////
//echo $cat;
//if ($cat > 0){
//$sql=mysql_query("SELECT state_abb,fips_code FROM smf_fips_states WHERE fips_code=$cat");
//$result=mysql_query($sql,$link) or die(mysql_error());
//echo "Error message = ".mysql_error();
//while ($row=mysql_fetch_array($result)) {
//$state_abb = $row['state_abb'];
//echo $cat;
//echo $state_abb;

////////// Starting of second drop downlist /////////
echo " County: <select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[county_name]'>$noticia[county_name]</option>";
echo "</select>";
////////////////// This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
<p>Start typing the name of the Industry you would like to search for:</p>
<p class="ui-widget"><label for="industry">Industry Code | Industry Name: </label>
<input type="text" id="industry" name="industry" maxlength="65" size="65" /></p>
<p class="ui-widget"><label for="industry_name">You selected: </label><input readonly="readonly" type="text" id="industry_name" name="industry_name" maxlength="50" size="50"/></p>
if (isset($_POST['submit'])) {
echo "<p>";
while (list($key,$value) = each($_POST)){
echo "<strong>" . $key . "</strong> = ".$value."<br />";
echo "</p>";

echo "<input type=submit value=Submit>";
echo "</form>";


Please Login to post your reply or start a new topic