sql - how do I use a string returned as an ajax response to assign to a php variable -
i select option drop down menu(id="field"), , on basis of value wish generate drop down menu, use ajax retrieve value of field1 input. function is:
function showbranches(degree) { var xmlhttp=false; if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.open("post","sors/sendegree.php?degree="+degree,true); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readystate==4 && xmlhttp.status == 200) { document.getelementbyid('br').innerhtml=xmlhttp.responsetext; } } xmlhttp.send(null); }
code in sendegree.php file simply
<?php echo $_request['degree']; ?>
now try receive string returned ajax code php variable using statement:
<?php $state="<span id=\"br\"></span>"; echo $state; ?>
now problem is, first statement echo works fine, not able use $state variable in sql query below
$get_cty=mysql_query("select * abc city='$state'")or die(mysql_error());
you need concatenate variable
try this
$get_cty=mysql_query("select * abc city='".$state."'") or die(mysql_error());
how learned in college whenever needed variable value in query added '".."'
after equals sign put variable in middle.
hope helps.
Comments
Post a Comment