Search the Community
Showing results for tags 'ajaz'.
-
When i am using this in my code and run getuser.php file the i am getting a drop down, a default table and a notice that is Undefined index: q in C:\wamp\www\sample\getuser.php on line 43 and when i select any name from drop down then there is making one more same drop down,and a new table which is working properly. But Problem is that what about the previous dropdown, table and notice. <html> <head> <script type="text/javascript"> 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 && xmlhttp.status == 200) { document.getElementById("txtHint").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "getuser.php?q=" + str, true); xmlhttp.send(); } </script> </head> <body> <form> <select name="users" onchange="showUser(this.value)"> <option value="">Select a person:</option> <option value="1">Peter Griffin</option> <option value="2">Lois Griffin</option> <option value="3">Glenn Quagmire</option> <option value="4">Joseph Swanson</option> </select> </form> <br/> <div id="txtHint"> <b>Person info will be listed here.</b> </div> </body> </html> <?php $q=$_GET["q"]; mysql_connect('localhost', 'root', ''); mysql_select_db("sample"); $sql="SELECT * FROM user WHERE id = '".$q."'"; $result = mysql_query($sql); echo "<table border='1'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['Age'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close(); ?>