Link to home
Start Free TrialLog in
Avatar of Larry Vollmer
Larry Vollmer

asked on

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

Avatar of tdot
tdot

i reomoved extra semicolon

$result = mysql_query("select * from taxpain where State != '' ORDER BY State");
Avatar of hielo
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`");
$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.

Avatar of Larry Vollmer

ASKER

no luck with either of those solutions. Hielo - the db name is populated in the file, i took it out for security purposes here.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jackpot!!!! Man you are a lifesaver.