Jump to content

- breaking querystring values when requesting xml documents :(


Greywacke
 Share

Recommended Posts

hi there,i have ran into the problem of querystring values, containing a "-", causing requesting this value to retrieve an empty string! :)despite using encodeURIComponent in the javascript, and sending the query string as "?q=3&Year=1999-2007" - Year is retrieved as "" :)the previous 3 requests send perfectly - such as "?q=0" to retrieve makes (which have 0 as parent), "?q=1&Make=FORD" to retrieve models (which have the sent make as parent), "?q=2&Model=F450" to retrieve years (which have the selected model as parent) - it just seems when i try include - in a querystring value for the year values in the database, it cancels the whole value out 0oan example of the compiled query for this is:

SELECT * FROM 3_serviceattributes WHERE bigint_AttributeServiceID = 1 AND CONCAT(",",bigint_AttributeParentID,",") LIKE CONCAT("%,",(SELECT bigint_AttributeID FROM 3_serviceattributes WHERE text_AttributeDescription = "CabSize" AND text_AttributeValue = ""),",%") ORDER BY text_AttributeDescription ASC, text_AttributeValue ASC;NOTICE #0500: An empty result set was returned by the query defined in /home/dwtphovu/public_html/truckcapxchange.com/ajax_attribs.php on line 21

the php xml generating code is as follows:

<?php/*TRUCKCAPXCHANGE ATTRIBUTE AJAX XML RESPONSEVersion 2.2.5*///set_time_limit(0);include("../intellisource.co.za/prod_5683194816/includes/content/dwtphovu_f3rr37y.php");$q = $_GET["q"];if (is_numeric($q)) {	if ($q > 4 || $q < 0) {		$q = 0;	}} else {	$q = 0;}function getrecords($data) {	$search = (is_array($data))?				"CONCAT(\",\",bigint_AttributeParentID,\",\") LIKE CONCAT(\"%,\",(SELECT bigint_AttributeID FROM 3_serviceattributes WHERE text_AttributeDescription = \"".$data[0]."\" AND text_AttributeValue = \"".$data[1]."\"),\",%\")"				:				"bigint_AttributeParentID = ".$data;	$sql = "SELECT * FROM 3_serviceattributes WHERE bigint_AttributeServiceID = 1 AND ".$search." ORDER BY text_AttributeDescription ASC, text_AttributeValue ASC;";	$result = mysql_query_errors($sql , $conn , __FILE__ , __LINE__ , true );	if ($result) {		while ($row = mysql_fetch_array($result)) {			echo "	<attrib name=\"".$row["text_AttributeDescription"]."\" value=\"".$row["text_AttributeValue"]."\" />\n";		}	}}header("Content-type: text/xml; charset=utf-8");echo "<?xml version=\"1.0\"?>\n";echo "<root>\n";switch ($q) {	case 1: // load models		getrecords(array("Make",$_GET["Make"]));		break;	case 2: // load years		getrecords(array("Model",$_GET["Model"]));		break;	case 2: // load cabsizes		getrecords(array("Year",$_GET["Year"]));		break;	case 3: // load bedsizes		getrecords(array("CabSize",$_GET["CabSize"]));		break;	default: // load makes		getrecords(0);}echo "	<sql>".xmlentities( ( (is_array($sql))?join("\n",$sql):$sql ) )."</sql>\n";echo "</root>";mysql_close($conn);?>

and the javascript ajaxRequest function is as follows:

function ajaxRequest(obj) {	var job = obj.name;	switch (job) {		case "Model": // get models			posAjax(obj);			var i = document.truckcap.Make.selectedIndex;			if (i>0) {				var poststr = "?q=1" +							  "&Make=" + encodeURIComponent(document.truckcap.Make.options[i].text);				alert(poststr);				return makeRequest("GET", "ajax_attribs.php", poststr);			} else {				document.getElementById("ajaxbg").style.visibility = "hidden";				return false;			}			break;		case "Year": // get years			posAjax(obj);			var i = document.truckcap.Model.selectedIndex;			if (i>0) {				var poststr = "?q=2" +							  "&Model=" + encodeURIComponent(document.truckcap.Model.options[i].text);				alert(poststr);				return makeRequest("GET", "ajax_attribs.php", poststr);			} else {				document.getElementById("ajaxbg").style.visibility = "hidden";				return false;			}			break;		case "CabSize": // get cabsizes			posAjax(obj);			var i = document.truckcap.Year.selectedIndex;			if (i>0) {				var poststr = "?q=3" +							  "&Year=" + encodeURIComponent(document.truckcap.Year.options[i].text);				alert(poststr);				return makeRequest("GET", "ajax_attribs.php", poststr);			} else {				document.getElementById("ajaxbg").style.visibility = "hidden";				return false;			}			break;		case "BedSize": // get bedsizes			posAjax(obj);			var i = document.truckcap.CabSize.selectedIndex;			if (i>0) {				var poststr = "?q=4" +							  "&CabSize=" + encodeURIComponent(document.truckcap.CabSize.options[i].text);				alert(poststr);				return makeRequest("GET", "ajax_attribs.php", poststr);			} else {				document.getElementById("ajaxbg").style.visibility = "hidden";				return false;			}			break;		default: // get makes			posAjax(obj);			var poststr = "?q=0";			alert(poststr);			return makeRequest("GET", "ajax_attribs.php", poststr);	}}

i can't seem to find anything googling on this, or how to resolve... any ideas? :/ the xml is generated by php and here whenever i use $_GET["Year"] - a blank value is returned!somebody please help!

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

ah ok... i see the mistake now. in the select case of the php xml generator, there were two instances of case 2: !it was supposed to be 3 and continue to 4 - this has now been resolved! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...