This issue has me absolutely stumped.

I have a drop-box on my site that contains 26 options (each options being a letter of the alphabet). This drop-box is being used to sort a database full of records by the records that correspond with the selected letter chosen. The "onchange" event triggers a javascript function that runs a bit of AJAX.

There are two other drop-boxes that are for sorting by column and sort in ascending/descending order. So the letter sort drop-box calls the javascript function while passing "alphaSort" parameter.

This function then grabs the selected value. Then it puts it into a url as shown:

function changeSort(sortType)
{
	value = document.getElementById(sortType).value;
	
	var url = "../validation/sorting.php";
	url = url + "?value=" + value;
	url = url + "&type=" + sortType;
	url = url + "&sid=" + Math.random();
	
	xmlhttp.onreadystatechange = stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);	
	
	function stateChanged()
	{
		if (xmlhttp.readyState==4)
		{
			response = xmlhttp.responseText;
		}
	}
	
	function GetXmlHttpObject()
	{
		if (window.XMLHttpRequest)
		{
			// code for IE7+, Firefox, Chrome, Opera, Safari
			return new XMLHttpRequest();
		}

		if (window.ActiveXObject)
		{
			// code for IE6, IE5
			return new ActiveXObject("Microsoft.XMLHTTP");
		}

		return null;
	}
}

FireBug shows that the sortType and value variables are being successfully passed through to the URL.

On the server-side file (sorting.php) is where nothing works.

I have the two gets:

$value = $_GET['value'];
$type = $_GET['type'];

Those two variables ($value, $type) do NOT contain any data. I did the following echo:

echo "Type: '" . $type . "' | Value: '" . $value . "'";

The echo returned: "Type: '' | Value: ''"

However, in Firebug, the AJAX response from the echo shows the data I want.

What's also very strange is I have is after I use the two $_GET's, I'm running this SQL query:

$query = "UPDATE Temp SET " .
		 $type . " = '" . $value . "' " .
		 "WHERE Username = '" . $_COOKIE['loginUser'] . "'";
	$result = mysql_query($query) or die(mysql_error());

It goes straight to the "die" and tells me basically there's no data in the $type and $value variables. HOWEVER, when I check out my database via phpMyAdmin, the data was actually updated to the table....

Please help

Zurompeta,

You are right, the symptoms are very odd.

The only thing that would make any sense to me is if some code higher up in sorting.php was doing the sql job and then destroying $_GET before the code you posted.

Does the page have one or more includes at the top? If so, then look inside and see what's going on.

Another idea: You could try changing $_GET to $_REQUEST all through and see if the issue persists. I can't see that it should make a difference but if it does, then we'll all have to out our thinking caps on.

Airshow

Thanks for the reply!

I'm including two files in the php file. However, I've tried putting the $_GET's before and after the files are including and still nothing. Also I have tried the $_REQUEST already with no success :(.

To help further, here's the top chunk of code in the PHP file:

require_once("../include/include.php");
	require_once("../clients/" . $_COOKIE['loginCompany'] . "/FF/config.php");

	OpenConnection($hostname, $database, $password);

	$value = $_GET['value'];
	$type = $_GET['type'];

	echo "Type: '" . $type . "' | Value: '" . $value . "'";
	$query = "UPDATE Temp SET " .
		 $type . " = '" . $value . "' " .
		 "WHERE Username = '" . $_COOKIE['loginUser'] . "'";
	$result = mysql_query($query) or die(mysql_error());

Zurompeta,

Mmm, odd. I can only suggest a diagnostic approach.

Backup sorting.php then strip the original down to the bare bones:

<?php
$value = $_GET['value'];
$type = $_GET['type'];
echo "Type: '" . $type . "' | Value: '" . $value . "'";
?>

Also replace your three-line AJAX block in javascript with location.href = url; . That way you will see the page on screen, not as an AJAX response.

See what it yields.

If it still returns blanks, then ..... I'm not sure .... I guess the fault is client-side.

If it displays your originall data as you would expect, then rebuild the server-side (php) code piecemeal and see when it breaks.

From the sound of it, you might have tried some or all of this already but that's all I can think of for now.

Good luck.

Airshow

Hmm, the barebone diagnostics sounds like a good idea. I will start with the PHP file as you instructed. I'll keep you up-to-date. :)

LOL!

Okay, I fudged up.

The one IMPORTANT part I left out was the output from the AJAX was going into an iFrame. In the "changeSort()" I mentioned above dynamically set the URL of the iFrame, but it set it to "validation/sorting.php?". So while the AJAX response was correctly displaying the proper information, the iFrame was setup incorrectly.

Man I hate stupid small mistakes.

My motto with programming is "The smallest mistakes cause the biggest problems". This is yet another to add to my list lol.

Well thanks so much for assisting :)

That's cool Zurom, we've all been there.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.