Syntax problem

I have a php/ajax script. I have copied itbelow. The physical page is right here:

http://tinyurl.com/y6q9ej4

This is an ajax script that populates a second select box based on choices from the first select box. I have populated the jax data from a MySQL database.

The script breaks when I run this query:

$result = mysql_query("select * from taxpain where State != '' ORDER BY State;");


but if I run this query:
$result = mysql_query("select * from taxpain where State != ''  OR state = 'Alabama' OR state = 'Arizona' ORDER BY State;");

it works fine. Here is an example of a page like that: http://tinyurl.com/y77rofu

Is there something obviously wrong in the source code that would cause the script to break when I run the larger query?

<?php
if( isset($_POST) && !empty($_POST) )
{
	print_r($_POST);
	exit;
}
?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
          xml:lang="en"
          lang="en">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script>
<script type="text/javascript" src="http://dev.chayachronicles.com/jquery/cascade/jquery.cascade.js"></script>
<script type="text/javascript" src="http://dev.chayachronicles.com/jquery/cascade/jquery.cascade.ext.js"></script>
<script type="text/javascript" src="http://dev.chayachronicles.com/jquery/cascade/jquery.templating.js"></script>
<script type="text/javascript">
                        var list1 = [
                              <?
//connect to mysql
//change user and password to your mySQL name and password

mysql_connect("", "", "") OR DIE("Unable to connect to the database"); 
	
//select which database you want to edit
mysql_select_db("");

//select the table
$result = mysql_query("select * from taxpain where State != '' ORDER BY State;");

//grab all the content
while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $state=$r["State"];
   $county=$r["County"];
   $ajaxvalue=$r["ajaxvalue"];

   
   //display the row
   echo "{'When':'$state','Value':'$ajaxvalue','Text':'$county'},\n";
}

?>


                                
                                ];

						var list1 = [	
						                              <?
//connect to mysql
//change user and password to your mySQL name and password

mysql_connect("", "", "") OR DIE("Unable to connect to the database"); 
	
//select which database you want to edit
mysql_select_db("");

//select the table
$result = mysql_query("select * from taxpain where County != '';");

//grab all the content
while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $state=$r["State"];
   $county=$r["County"];
   $ajaxvalue=$r["ajaxvalue"];

   
   //display the row
   echo "{'When':'$state','Value':'$county','Text':'$county'},\n";
}
		?>	

                               
                                ];                               
                        function commonTemplate(item) {
                                return "<option value='" + item.Value + "'>" + item.Text + "</option>"; 
                        };
                        function commonTemplate2(item) {
                                return "<option value='" + item.Value + "'>***" + item.Text + "***</option>"; 
                        };
                        
                        function commonMatch(selectedValue) {
                                return this.When == selectedValue; 
                        };
                        
                </script>
<script type="text/javascript">
                jQuery(document).ready(function()
                {       
                        jQuery("#simple_child").cascade("#simple",{                                     
                                list: list1,                    
                                template: commonTemplate,
                                match: commonMatch                      
                        });
                });
        </script>
<style type="text/css">
                        .cascade-loading        
                        {                                                                                                                                               
                                background: transparent url("indicator.gif") no-repeat center;                                  
                        }
                </style>
</head>
<body>
<form action="variable.php" method="post">
  <h2>Simple</h2>
  <div>
    <label>Parent
    <select id="simple" name="simple">
      <option SELECTED value="nothing" >Choose a State</option>
      <option value="Alabama">Alabama</option>
      <option value="Alaska">Alaska</option>
      <option value="Arizona">Arizona</option>
      <option value="California">California</option>
      <option value="Colorado">Colorado</option>
      <option value="Connecticut">Connecticut</option>
      <option value="Delaware">Delaware</option>
      <option value="District of Columbia">District of Columbia</option>
      <option value="Florida">Florida</option>
      <option value="Georgia">Georgia</option>
      <option value="Hawaii">Hawaii</option>
      <option value="Idaho">Idaho</option>
      <option value="Illinois">Illinois</option>
      <option value="Indiana">Indiana</option>
      <option value="Iowa">Iowa</option>
      <option value="Kansas">Kansas</option>
      <option value="Kentucky">Kentucky</option>
      <option value="Louisiana">Louisiana</option>
      <option value="Maine">Maine</option>
      <option value="Maryland">Maryland</option>
      <option value="Massachusetts">Massachusetts</option>
      <option value="Michigan">Michigan</option>
      <option value="Minnesota">Minnesota</option>
      <option value="Mississippi">Mississippi</option>
      <option value="Missouri">Missouri</option>
      <option value="Montana">Montana</option>
      <option value="Nebraska">Nebraska</option>
      <option value="Nevada">Nevada</option>
      <option value="New Hampshire">New Hampshire</option>
      <option value="New Jersey">New Jersey</option>
      <option value="New Mexico">New Mexico</option>
      <option value="New York">New York</option>
      <option value="North Carolina">North Carolina</option>
      <option value="North Dakota">North Dakota</option>
      <option value="Ohio">Ohio</option>
      <option value="Oklahoma">Oklahoma</option>
      <option value="Oregon">Oregon</option>
      <option value="Pennsylvania">Pennsylvania</option>
      <option value="Puerto Rico">Puerto Rico</option>
      <option value="Rhode Island">Rhode Island</option>
      <option value="South Carolina">South Carolina</option>
      <option value="South Dakota">South Dakota</option>
      <option value="Tennessee">Tennessee</option>
      <option value="Texas">Texas</option>
      <option value="Utah">Utah</option>
      <option value="Vermont">Vermont</option>
      <option value="Virginia">Virginia</option>
      <option value="Washington">Washington</option>
      <option value="West Virginia">West Virginia</option>
      <option value="Wisconsin">Wisconsin</option>
      <option value="Wyoming">Wyoming</option>
    </select>
    </label>
    <label>Child
    <select id="simple_child" name="simple_child">
      <option value='nope1'>Select a County</option>
    </select>
    </label>
    <p>
      <input type="submit" name="Submit" value="Submit" />
    </p>
  </div>
</form>
<h2 id="ajax_header">&nbsp;</h2>
</body>
</html>

Open in new window

lvollmerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tdotCommented:
i reomoved extra semicolon

$result = mysql_query("select * from taxpain where State != '' ORDER BY State");
0
hieloCommented:
You have:
mysql_select_db("");


be sure to put you db name. Also put backticks on your State field:
$result = mysql_query("select * from `taxpain` where `State` != '' ORDER BY `State`");
0
tdotCommented:
$result = mysql_query("select * from taxpain where State != 'null' ORDER BY State");
also check what your default is for the state column  in your table schema and add that instead of nothing.

0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

lvollmerAuthor Commented:
no luck with either of those solutions. Hielo - the db name is populated in the file, i took it out for security purposes here.
0
hieloCommented:
change these:
   $state=$r["State"];
   $county=$r["County"];
   $ajaxvalue=$r["ajaxvalue"];


to:
   $state= str_replace( "'","\\'", $r["State"]);
   $county=str_replace( "'","\\'", $r["County"]);
   $ajaxvalue=str_replace( "'","\\'", $r["ajaxvalue"]);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lvollmerAuthor Commented:
Jackpot!!!! Man you are a lifesaver.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.