Off topic:Mysql query is not working with drop down option
0
0
Entering edit mode
5.9 years ago

hello all Can anybody help me out with the Php and Mysql code. The mysql query does not fetch data from the database. The example file are mentioned below:

This is the code for making a drop down list. <html> <head>

<script> function showUser(str) { if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { 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 (this.readyState == 4 && this.status == 200) { document.getElementById("txtHint").innerHTML = this.responseText; } }; xmlhttp.open("GET","isolates.php?q="+str,true); xmlhttp.send(); } } </script>

</head> <body> <select name="q" onchange="showUser(this.value)"> <option value="">Select a strain:</option> <option value="1">ABNIH5</option> <option value="2">ABNIH5</option> <option value="3">ABNIH5</option> <option value="4">ABNIH5</option> </select> </form>

Strain info will be listed here...

</body> </html>

and this is another code to fetch data. $q = $_GET['q']; $dbhost = 'abc'; $dbuser = 'abc'; $dbpass = 'abc'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (! $conn) { die ('could not connect: ' . mysql_error()); }

if (!mysql_select_db('xyz', $conn)) { echo 'Could not select database'; exit; }

$sql= "SELECT Genome_id,Genome_name,Genome_status,Completion_date,Publication FROM tablename WHERE Strain_id LIKE '%".$q."%'"; $result = mysql_query($sql, $conn); echo "

"; if (!$result) { echo "DB Error, could not query the database\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while($row = mysql_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Genome_id Genome_name Genome_status Completion_date Publication
" . $row['Genome_id'] . "" . $row['Genome_name'] . "" . $row['Genome_status'] . "" . $row['Completion_date'] . "" . $row['Publication'] . "
";

?>

</body> </html>

software error • 482 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 3287 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6