Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Create ajax auto-suggest
    text
    copied!<p>I would like to create a very simple ajax auto-suggest which it can retrieve some data from database.</p> <p>You can see here :</p> <p><strong>index.php</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function suggest() { var txtSearch = document.getElementById('txtSearch').value; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject('MicrosoftXMLHTTP'); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { document.getElementById('myDiv').innerHTML = xmlhttp.responseText; } } var target = 'include.inc.php?txtSearch=' + txtSearch; xmlhttp.open('GET', target, true); xmlhttp.send(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="text" id="txtSearch" onkeyup="suggest();"/&gt; &lt;div id="myDiv"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>incldue.inc.php</strong></p> <pre><code>&lt;?php require_once 'connect.inc.php'; if (isset($_GET['txtSearch'])) { $txtSearch = $_GET['txtSearch']; getSuggest($txtSearch); } function getSuggest($text) { $sqlCommand = "SELECT `SurName` FROM `person` WHERE `SurName` LIKE '%$text%'"; $query = mysql_query($sqlCommand); $result_count = mysql_num_rows($query); while ($row = mysql_fetch_assoc($query)) { echo $row['SurName'].'&lt;br /&gt;'; } ?&gt; </code></pre> <p><strong>The problem :</strong></p> <p>Get following error on line 22, But i have no idea why :</p> <pre><code>Parse error: syntax error, unexpected end of file in C:\wamp\www\PHP_Ajax_Autosuggest\include.inc.php on line 22 </code></pre> <p><strong>P.S :</strong></p> <p>And i didn't mentioned <code>connect.inc.php</code> content, because it works fine.</p> <p>Any help would be great appreciated.</p>
 

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