Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Query doesn't work with amp (&) / %26 inside request?
    primarykey
    data
    text
    <p>OK, code returns results normally when there is no ( amp / &amp; / &amp; ) inside query:</p> <pre><code>example1 =&gt; BRAHAM BALDWIN AGRICULTURAL COLLEGE </code></pre> <p>is converted and query looks like => BRAHAM+BALDWIN+AGRICULTURAL+COLLEGE</p> <p>Example 1 => works normally and returns => This school is in Alabama</p> <pre><code>example2 query =&gt; BRYANT &amp; STRATTON BUSINESS INSTITUTE - BUFFALO </code></pre> <p>is converted and query looks like => BRYANT+%26+STRATTON+BUSINESS+INSTITUTE+-+BUFFALO</p> <p>Example 2 => doesn't return anything, I'm quite sure that's because of %26 (amp / &amp;)...</p> <p>Code in funcs.php:</p> <pre><code>require 'dbconnect.php'; $q = $_GET["q"]; $sql = "SELECT * FROM bl_zrify WHERE Name = '".$q."'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { if ($row['State'] == '') { $SchoolState = 'Unknown'; } else if ($row['State'] == 'AL') { $SchoolState = 'Alabama'; } else if ($row['State'] == 'AK') { $SchoolState = 'Alaska'; } else if ($row['State'] == 'AZ') { $SchoolState = 'Arizona'; } else if ($row['State'] == 'AR') { $SchoolState = 'Arkansas'; } print 'This school is in'; print $SchoolState; } </code></pre> <p>PHP code get executed when we type text into => </p> <pre><code>&lt;input name="SchoolName" type="text" maxlength="50" size="30" id="SchoolName" value="" onfocus="showVal(this.value);" /&gt; </code></pre> <p>And javascript which we use to pass the string to PHP funcs.php:</p> <pre><code>function showVal(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } 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 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","funcs.php?q="+str.replace("&amp;", "%26").replace(/ /g, "+"),true); xmlhttp.send(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload