this is my table subjects in lecturer database
No subject credit_hour
1 (111) AAA 4
2 (222) BBB 3
3 (222) CCC 4
4 (333) DDD 3
this is my testing1.php
<?php
$conn = mysql_connect('localhost','root','password');
mysql_select_db('lecturer');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<html>
<head>
<script>
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","testing3.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="subjects" onchange="showUser(this.value)">
<option value="">Select a subject:</option>
<?php $result= mysql_query('SELECT * FROM subjects'); ?>
<?php while($row= mysql_fetch_assoc($result)) {
$list=array($row['subject'],$row['credit_hour']);
?>
<option>
<?php echo htmlspecialchars($row['subject'] ); ?>
<?php echo htmlspecialchars($row['credit_hour'] ); ?>
</option>
<?php } ?>
</select>
</form>
<br>
<div id="txtHint"><b>subject info will be listed here.</b></div>
</body>
</html>
this is my testing3.php
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','password','lecturer');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"lecturer");
$sql="SELECT * FROM subjects WHERE No = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table border='1'>
<tr>
<th>Subject</th>
<th>Credit_hour</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['subject'] . "</td>";
echo "<td>" . $row['credit_hour'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
the problem is that when i select (111)AAA 4
it should be appearing a table which is located in testing3.php but it didnt fetch any data in the table
thank you