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