Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I've tweaked your files slightly, you shouldn't be using mysql_ or the mysqli_ functions any more, just don't... And you certainly shouldn't be using mysql function in one file and mysqli functions in the other... I've switched them over to use PDO, you're script now isn't susceptible to SQL injection, and as far as I can tell it works just fine.</p> <p>index.html</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script&gt; function showUser(str) { if(str=="") { document.getElementById("txtHint").innerHTML=""; return; } if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { 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","getuser.php?q="+str,true); xmlhttp.send(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form&gt; &lt;?php try { $dbh = new PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger'); } catch (PDOException $e) { echo 'Connection failed: ' . $e-&gt;getMessage(); } $sql = "SELECT theater_name FROM theater;"; $sth = $dbh-&gt;prepare($sql); $sth-&gt;execute(); echo "&lt;select name='theater_name' id='course' onchange='showUser(this.value);'&gt;"; while($row = $sth-&gt;fetch(PDO::FETCH_ASSOC)) { echo "&lt;option value='" . $row['theater_name'] ."'&gt;" . $row['theater_name']. "&lt;/option&gt;"; } echo "&lt;/select&gt;"; ?&gt; &lt;/form&gt; &lt;br&gt; &lt;div id="txtHint"&gt;&lt;b&gt;Info&lt;/b&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>getuser.php</p> <pre><code>&lt;?php $q = strtolower(trim($_GET["q"])); try { $dbh = new PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger'); } catch (PDOException $e) { echo 'Connection failed: ' . $e-&gt;getMessage(); } $sql = 'SELECT address FROM theater WHERE LOWER(theater_name) = :q'; $sth = $dbh-&gt;prepare($sql); $sth-&gt;bindValue(':q', $q); $sth-&gt;execute(); echo "&lt;table border='1'&gt;&lt;tr&gt;&lt;th&gt;Firstname&lt;/th&gt;&lt;/tr&gt;"; while($row = $sth-&gt;fetch(PDO::FETCH_ASSOC)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" . $row['address'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; $dbh = null; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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