I am attempting to pass a parameter from javascript to a php file, use the parameter in my Where
clause in the php file and echo the results back to the calling page. Nothing is returned, and I am not sure if the issue lies in the javascript or the php.
This is what I have
PHP
$state = $_POST['state'];
$con = mssql_connect('Server','userid','pwd')
or die('Could not connect to the server!');
mssql_select_db('Partner')
or die('Could not select a database.');
$SQL = "SELECT * FROM [Table] WHERE [state] = '". $state. "'";
$result = mssql_query($SQL) or die('A error occured: ' . mysql_error());
echo $result
JavaScript (at least the relevant portion)
var name="TX"
xhr.open("GET", "Test.php?state="+name, true);
What needs to be changed in either the php file or the javascript so that this will properly return the value? It is valid sql as if I run the string in SSMS it returns properly. (yes it is 2 digit states being stored in the database also)
EDIT
I am reading the response like so
xhr.onreadystatechange = function(){ if (xhr.readyState == 4 && xhr.status==200)
{ document.getElementById("response").innerHTML = xhr.responseText; } }