0

So I am trying to pass back a couple values to a PHP page like this.

function showAccountInfo(obj){

    var value = obj.value;
    var content = obj.querySelector("option:checked").textContent;

    alert("value: " + value + " content: " + content);

    if(obj == ""){
        return;
    }
    else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("facilities").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","getinfo.php?=q"+value+"&c="+content, true);
        xmlhttp.send(); 
    }
}

When the alert goes off it shows me the correct values for each variable. However when I pass off that value to getinfo.php and use the variable value to complete a query and echo it out to the page it shows me it as empty.

$q = ($_GET['q']);

$sql = "SELECT *, account.account_name FROM facility "
 . "INNER JOIN account ON account.account_id = facility.account_id "
 . "WHERE facility.account_id = '".$q."'";

echo $sql;

Result: SELECT *, account.account_name FROM facility INNER JOIN account ON account.account_id = facility.account_id WHERE facility.account_id = ''

I had everything functioning properly prior my previous question.

2
  • Have you checked the generated URL is what you expect in the Net tab of your developer tools? Is the data in the response correct? Commented Mar 5, 2015 at 17:29
  • @Quentin just checked, the URL is giving me the correct data. Commented Mar 5, 2015 at 17:32

1 Answer 1

1

Your url is incorrectly formatted

Change

xmlhttp.open("GET","getinfo.php?=q"+value+"&c="+content, true);
                                ^

To

xmlhttp.open("GET","getinfo.php?q="+value+"&c="+content, true);
                                 ^

Note change of first =

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that was it..should have noticed that, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.