无法在javascript中写入for循环,也无法将数据上载到mysql

无法在javascript中写入for循环,也无法将数据上载到mysql,javascript,php,mysql,Javascript,Php,Mysql,我想为学生创建一个在线考试页面。问题要加载到javascript中,点击按钮后,答案需要上传到MySQL数据库 找不到错误,请帮助我 <style> div#test{ border:#000 1px solid; padding:10px 40px 40px 40px; } </style> <script> var res = <?= $r?>; var no =<?= $n?>; var pos = 0, test, test_s

我想为学生创建一个在线考试页面。问题要加载到javascript中,点击按钮后,答案需要上传到MySQL数据库

找不到错误,请帮助我

<style>
div#test{ border:#000 1px solid; padding:10px 40px 40px 40px; }
</style>
<script>
var res = <?= $r?>;
var no =<?= $n?>;
var pos = 0, test, test_status, question, choice, choices, chA, chB, chC, correct = 0;
var questions = [
                for(var a=0; a<=4; a++){
        [ "<?= $r[1]?>", "<?= $r[5]?>", "<?= $r[6]?>", "<?= $r[7]?>", "<?= $r[8]?>", "<?= $r[9]?>"]
                }
    ];
function _(x){
    return document.getElementById(x);
}
function renderQuestion(){
    test = _("test");
    if(pos >= questions.length){
        test.innerHTML = "<h2>You got "+correct+" of "+questions.length+" questions correct</h2>";
        _("test_status").innerHTML = "Test Completed";
        pos = 0;
        correct = 0;
        return false;
    }
    _("test_status").innerHTML = "Question "+(pos+1)+" of "+questions.length;
    question = questions[pos][1];
    chA = questions[pos][2];
    chB = questions[pos][3];
    chC = questions[pos][4];
    chD = questions[pos][5];
    test.innerHTML = "<h3>"+question+"</h3>";
    test.innerHTML += "<input type='radio' name='choices' value='A'> "+chA+"<br>";
    test.innerHTML += "<input type='radio' name='choices' value='B'> "+chB+"<br>";
    test.innerHTML += "<input type='radio' name='choices' value='C'> "+chC+"<br>";
    test.innerHTML += "<input type='radio' name='choices' value='C'> "+chD+"<br><br>";
    test.innerHTML += "<button onclick='checkAnswer()'>Submit Answer</button>";
}
function checkAnswer(){
    choices = document.getElementsByName("choices");
    for(var i=0; i<choices.length; i++){
        if(choices[i].checked){
            choice = choices[i].value;
        }
    }
    if(choice == questions[pos][4]){
        correct++;
    }
    pos++;
    renderQuestion();
}
window.addEventListener("load", renderQuestion, false);
</script>

div#test{边框:000 1px固体;填充:10px 40px 40px 40px;}
var res=;
var no=;
var pos=0,测试,测试状态,问题,选择,选择,chA,chB,chC,正确=0;
变量问题=[

对于(var a=0;a“找不到错误”?您到底有什么错误?是否没有输出?控制台中是否显示任何内容?存在许多“问题”。您将
test
设置为
(“test”);
而不是DOM节点,并且您从未实际将其插入页面。网页上没有显示输出。但是当我检查网页时,我可以在代码中看到php变量值。我认为for循环错误在for循环中。for(var a=0;请编辑您自己的问题,以添加有关您面临的实际错误的详细信息。
[“”、“”、“”、“”、“”、“”、“”、“”]
。我预测这将在JS中产生语法错误。您是否检查了浏览器控制台中的错误?它将只输出4个数组(同一个,重复4次),但没有声明任何用于保存它们的变量,也没有声明它们之间的分号。这太混乱了,我甚至无法确定您试图用这段代码实现什么。
声明了一个
,但除了用作计数器外,从未使用过,然后您只需重复PHP的相同输出4次。这应该包含您的问题数据吗?