网页无法显示php select 数据库sqlite3 里的东西。

我想让用户选择一个任务,网页会出现database里的信息。
比如选数学,网页上会以表格的形式出现db里数学的标签,用时,和日期。我大概是仿照这个网页弄的。(https://www.w3schools.com/php...)。
现在用户选数学,网页不会出现数学相关信息。
我不知道从那里找问题。谢谢解答!!
我的html 文件如下

<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","getuser.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>
</head>
<body>

<form>
<select name="TASK" onchange="showUser(this.value)">
  <option value="">Select a task:</option>
  <option value=“1”>MATH</option>
  <option value="2">ENGLISH</option>
 
  </select>
</form>


</body>
</html>

我的php文件叫getuser.php 如下
    <!DOCTYPE html>
<html>
<head>
<style>
table {
    width: 100%;
    border-collapse: collapse;
}

table, td, th {
    border: 1px solid black;
    padding: 5px;
}

th {text-align: left;}
</style>
</head>
<body>

<?php
$q = intval($_GET['q']);

class MyDB extends SQLite3{
    function _construct(){
        $this->open(‘CS1962.db’);
        }
    }
}
$db = new MyDB();
if(!$db){
    echo $db->lastErrorMsg();
}  else{
    echo "Opened database successfully\n";
}

$sql =<<<EOF
    SELECT * FROM MYTIME WHERE id = '".$q."'
EOF;

$ret = $db->query($sql);






echo "<table>
<tr>
<th>TASK</th>
<th>TAG</th>
<th>DURATION</th>
<th>DATE</th>

</tr>";

while($row = $ret->fetchArray(SQLITE3_ASSOC) ) {
    echo "<tr>";
    echo "<td>" . $row['TASK'] . "</td>";
    echo "<td>" . $row['TAG'] . "</td>";
    echo "<td>" . $row['DURATION'] . "</td>";
    echo "<td>" . $row['DATE'] . "</td>";
   
    echo "</tr>";
}
echo "</table>";
$db->close();
?>
</body>
</html>
阅读 2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题