Note that there are some explanatory texts on larger screens.

plurals
  1. POretrieve data from database mysql not working
    primarykey
    data
    text
    <p>Hi i am using the html dropdown's onchange event using ajax</p> <p>In the code i am using, should get the address column value when i change the drop down.</p> <p>but it is not working.What may have gone wrong?</p> <p>here is the code </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 ) { // 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", "getuser.php?q=" + str, true); xmlhttp.send(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form&gt; &lt;?php mysql_connect('localhost', 'tiger', 'tiger'); mysql_select_db('theaterdb'); $sql = "select theater_name from theater;"; $result = mysql_query($sql); echo "&lt;select name='theater_name' id='course' onchange='showUser(this.value);'&gt;"; while ( $row = mysql_fetch_array( $result ) ) { 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>Code for getuser.php</p> <pre><code>&lt;?php $q = $_GET["q"]; $con = mysqli_connect("localhost", "tiger", "tiger", "theaterdb"); if ( !$con ) { die('Could not connect: ' . mysqli_error( $con ) ); } mysqli_select_db( $con ); $sql = "SELECT address FROM theater WHERE theater_name = '".$q."'"; $result = mysqli_query( $con, $sql ); echo "&lt;table border='1'&gt; &lt;tr&gt; &lt;th&gt;Firstname&lt;/th&gt; &lt;/tr&gt;"; while( $row = mysqli_fetch_array( $result ) ) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" . $row['address'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysqli_close($con); ?&gt; </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.
 

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